willowpillow29's picture
Update app.py
cee220a verified
Raw
History Blame Contribute Delete
1.41 kB
# import gradio as gr
# def echo(message,history):
# return message
# chatbot = gr.ChatInterface(echo)
# chatbot.launch()
import gradio as gr
from huggingface_hub import InferenceClient
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
def respond(message, history):
response = ""
content = "You are a friendly chatbot that helps people plan their dream trips by giving them recommendations for places, local food, and local hidden gems. Keep the advice friendly, concise, and under 100 words. Example: user: where should I travel for spring break?, AI: You should travel to somewhere warm where you can relax and have fun. I recommend going to San Diego and enjoying beaches like La Jolla, while also exploring local charms like OldTown and visiting their small beach shops."
messages = [{"role": "system", "content": content}]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
for message_chunk in client.chat_completion(
messages,
max_tokens=150, #I want to keep the advice concise
temperature = 0.7, #higher for a more friendly personality
stream=True, # Crucial for streaming! [cite: 215]
):
token = message_chunk.choices[0].delta.content
response += token
yield response
chatbot = gr.ChatInterface(respond)
chatbot.launch(debug = True)