ChatbotLab / app.py
limeiz's picture
Update app.py
00a2dc5 verified
raw
history blame
1.19 kB
import gradio as gr
import random
from huggingface_hub import InferenceClient
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
#change the LLM
def respond(message, history):
messages = [{"role": "system", "content": "You are a friendly chatbot."}] #change the personality
if history:
messages.extend(history)
messages.append({"role":"user", "content": message})
response = client.chat_completion(
messages,
max_tokens=500,
temperature = 0
top_p = 0.1
)
# change length using max_tokens
print(response['choices'][0]['message']['content'].strip())
return response['choices'][0]['message']['content'].strip()
def random_message(message, history):
choices = ["yes.", "no.", "it is certain","without a doubt","outlook good","ask again later", "better not tell you now","very doubtful","don't count on it","my sources say no","outlook not so good","very doubtful","reply hazy, try again", "cannot predict now"]
chat_answer = random.choice(choices)
return chat_answer
print("Hello, World!")
chatbot = gr.ChatInterface(respond, type = "messages")
chatbot.launch(debug=True)