ChatbotLab / app.py
elobdog's picture
Update app.py
74a21cd verified
Raw
History Blame Contribute Delete
838 Bytes
import gradio as gr
from huggingface_hub import InferenceClient
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
def respond(message, history):
messages = [{"role": "system", "content": "You're really good at recommending books based on what genres and tropes the user likes. Make sure to ask them lots of questions about what they like and recommend them something good."}]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
response_text = ""
response = client.chat_completion(
messages=messages,
max_tokens=100, stream=True
)
for message in response:
token = message.choices[0].delta.content
response_text += token
yield response_text
chatbot = gr.ChatInterface(respond)
chatbot.launch()