Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,14 +70,14 @@ print(top_results)
|
|
| 70 |
# HUGGING FACE PROJECT
|
| 71 |
client = InferenceClient("Qwen/Qwen2.5-72B-instruct")
|
| 72 |
|
| 73 |
-
def respond(message, history): # Generate a response using the most relevant travel info chunks
|
| 74 |
top_chunks = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 75 |
str_top_chunks = "\n".join(top_chunks)
|
| 76 |
|
| 77 |
messages = [
|
| 78 |
{
|
| 79 |
"role": "system",
|
| 80 |
-
"content": f"You are a friendly travel agent. Base your response on {top_chunks}. Don't create anything, only take from our data. Help the customer to plan outfits for their vacation and etiquette for the country."
|
| 81 |
},
|
| 82 |
{
|
| 83 |
"role": "user",
|
|
@@ -98,12 +98,18 @@ def respond(message, history): # Generate a response using the most relevant tra
|
|
| 98 |
|
| 99 |
return response["choices"][0]["message"]["content"].strip()
|
| 100 |
|
|
|
|
| 101 |
# SURVEY
|
| 102 |
-
def submit_survey(name,
|
| 103 |
-
print(f"Survey received - Name: {name},
|
| 104 |
-
return f"Thank you, {name}! Your survey response has been recorded."
|
|
|
|
| 105 |
|
| 106 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
gr.Markdown("## Survey")
|
| 108 |
|
| 109 |
with gr.Column():
|
|
@@ -114,14 +120,22 @@ with gr.Blocks() as demo:
|
|
| 114 |
survey_output = gr.Textbox(label="Response", interactive=False)
|
| 115 |
|
| 116 |
submit_btn.click(
|
| 117 |
-
fn=
|
| 118 |
inputs=[name, country],
|
| 119 |
-
outputs=survey_output
|
| 120 |
)
|
| 121 |
|
| 122 |
gr.Markdown("---")
|
| 123 |
gr.Markdown("## Chatbot")
|
| 124 |
-
gr.ChatInterface(respond)
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
demo.launch()
|
|
|
|
| 70 |
# HUGGING FACE PROJECT
|
| 71 |
client = InferenceClient("Qwen/Qwen2.5-72B-instruct")
|
| 72 |
|
| 73 |
+
def respond(message, history, name, country): # Generate a response using the most relevant travel info chunks
|
| 74 |
top_chunks = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 75 |
str_top_chunks = "\n".join(top_chunks)
|
| 76 |
|
| 77 |
messages = [
|
| 78 |
{
|
| 79 |
"role": "system",
|
| 80 |
+
"content": f"You are a friendly travel agent. Base your response on {top_chunks}. The user's name is {name} and they are traveling to {country}. Don't create anything, only take from our data. Help the customer to plan outfits for their vacation and etiquette for the country."
|
| 81 |
},
|
| 82 |
{
|
| 83 |
"role": "user",
|
|
|
|
| 98 |
|
| 99 |
return response["choices"][0]["message"]["content"].strip()
|
| 100 |
|
| 101 |
+
|
| 102 |
# SURVEY
|
| 103 |
+
def submit_survey(name, country):
|
| 104 |
+
print(f"Survey received - Name: {name}, Country: {country}")
|
| 105 |
+
return f"Thank you, {name}! Your survey response has been recorded.", name, country
|
| 106 |
+
|
| 107 |
|
| 108 |
with gr.Blocks() as demo:
|
| 109 |
+
name_state = gr.State()
|
| 110 |
+
country_state = gr.State()
|
| 111 |
+
chat_state = gr.State([])
|
| 112 |
+
|
| 113 |
gr.Markdown("## Survey")
|
| 114 |
|
| 115 |
with gr.Column():
|
|
|
|
| 120 |
survey_output = gr.Textbox(label="Response", interactive=False)
|
| 121 |
|
| 122 |
submit_btn.click(
|
| 123 |
+
fn=submit_survey,
|
| 124 |
inputs=[name, country],
|
| 125 |
+
outputs=[survey_output, name_state, country_state]
|
| 126 |
)
|
| 127 |
|
| 128 |
gr.Markdown("---")
|
| 129 |
gr.Markdown("## Chatbot")
|
|
|
|
| 130 |
|
| 131 |
+
chatbot = gr.Chatbot()
|
| 132 |
+
msg = gr.Textbox(label="Ask me anything about your trip!")
|
| 133 |
+
send_btn = gr.Button("Send")
|
| 134 |
+
|
| 135 |
+
send_btn.click(
|
| 136 |
+
fn=respond,
|
| 137 |
+
inputs=[msg, chat_state, name_state, country_state],
|
| 138 |
+
outputs=chatbot
|
| 139 |
+
)
|
| 140 |
|
| 141 |
demo.launch()
|