kwkchatbot / app.py
svarshney25's picture
Update app.py
1f43b12 verified
Raw
History Blame Contribute Delete
929 Bytes
import gradio as gr
import random
from huggingface_hub import InferenceClient
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
def respond(message, history):
messages = [{"role": "system", "content": "You are a travel advisor helping plan a trip to Morocco. Give a week long itinerary. Focus on activities, not food."}]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
# response = client.chat_completion(
# messages,
# max_tokens=100,
# temperature = 1.5,
# top_p = 0.34
# )
response = ""
for msg in client.chat_completion(messages, stream=True):
token = msg.choices[0].delta.content
if token is not None:
response += token
yield response #response.choices[0].message.content.strip()
chatbot = gr.ChatInterface(respond, title="my bot")
chatbot.launch(debug=True)