willowpillow29/firstEverChatBot
0
1# import gradio as gr2 3# def echo(message,history):4# return message5 6# chatbot = gr.ChatInterface(echo)7# chatbot.launch()8 9 10 11import gradio as gr12from huggingface_hub import InferenceClient13 14client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")15 16def respond(message, history):17 response = ""18 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."19 messages = [{"role": "system", "content": content}]20 21 if history:22 messages.extend(history)23 24 messages.append({"role": "user", "content": message})25 26 for message_chunk in client.chat_completion(27 messages,28 max_tokens=150, #I want to keep the advice concise 29 temperature = 0.7, #higher for a more friendly personality30 stream=True, # Crucial for streaming! [cite: 215]31 ):32 token = message_chunk.choices[0].delta.content33 response += token34 yield response35 36 37 38chatbot = gr.ChatInterface(respond) 39 40chatbot.launch(debug = True)