File size: 1,278 Bytes
8ab3871
cee5498
8ab3871
 
 
 
 
3e4e428
53bde7e
dfd37ad
 
53bde7e
978e669
cee5498
0fc4309
104eec5
 
 
 
 
 
 
 
649ecca
f51cb6e
104eec5
 
 
9720b15
8ab3871
 
 
 
0fc4309
8ec9d67
 
104eec5
 
34f5b6f
8ab3871
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gradio as gr
import os
from huggingface_hub import InferenceClient

"""
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
"""

client = InferenceClient("nvidia/Llama-3.1-Nemotron-8B-UltraLong-4M-Instruct") 

api_key = os.environ.get("NINJA_API")
   
PERSONALITY = os.environ.get("CHATBOT_PERSONALITY")

def role(message, history):
   
    history.append({"role": "user", "content": message})

    prompt = PERSONALITY + "\n\n"
    for msg in history:
        prompt += f"{msg['role'].capitalize()}: {msg['content']}\n"
    prompt += "Role:"

    response = client.text_generation(prompt, max_new_tokens=250)
   
    history.append({"role": "assistant", "content": response})

    return history, history

"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""
demo = gr.ChatInterface(
    role,
    title="Shinobi - Japanese Culture Specialist",
    description="A chatbot specializing in Japanese culture.",
    chatbot=gr.Chatbot(),
    examples=["Tell me about the history of Samurai", "What is Bushido?", "Recommend a Japanese film"]
)


if __name__ == "__main__":
    demo.launch()