File size: 1,411 Bytes
431acf9
 
 
 
 
 
 
 
 
 
f9072a5
431acf9
 
76d357d
431acf9
 
23565b0
c87942d
878812d
431acf9
 
 
 
 
23565b0
 
431acf9
23565b0
 
4b42917
23565b0
cee220a
71cab11
 
23565b0
 
f9072a5
c840f03
f9072a5
4b42917
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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)