Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,7 +45,7 @@ questions_europe = [
|
|
| 45 |
]),
|
| 46 |
("2. What type of souvenir do you want to bring home?", [
|
| 47 |
("A", "A vintage print from a street artist."),
|
| 48 |
-
("B", "A quirky gadget or handmade
|
| 49 |
("C", "A handmade bracelet and beach sarong."),
|
| 50 |
("D", "A t-shirt from a local streetwear brand."),
|
| 51 |
("E", "A flamenco fan or mosaic-tiled trinket.")
|
|
@@ -116,50 +116,52 @@ def parse_date(date_str):
|
|
| 116 |
parsed_date = dateparser.parse(date_str, settings={'PREFER_DATES_FROM': 'future'})
|
| 117 |
return parsed_date if parsed_date else None
|
| 118 |
|
| 119 |
-
def respond(destination, transportation, date, preference, include_options
|
| 120 |
global travel_guide_output
|
|
|
|
| 121 |
|
| 122 |
prompt = f"""
|
| 123 |
**Travel Plan Details:**
|
|
|
|
| 124 |
- **To:** {destination}
|
| 125 |
- **Transportation:** {transportation}
|
| 126 |
- **Travel Date:** {date}
|
| 127 |
- **Budget Preference:** {preference}
|
| 128 |
-
-**If minors are there**{minors}
|
| 129 |
- **Additional Info:** {', '.join(include_options) if include_options else 'None'}
|
| 130 |
-
|
| 131 |
-
The trip is for {length_input} and {minors_included} to there being minors
|
| 132 |
"""
|
| 133 |
-
messages = [{"role": "system", "content": prompt}]
|
| 134 |
-
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
response = ""
|
| 149 |
-
for message in client.chat_completion(
|
| 150 |
-
messages, max_tokens = 4096, stream=True
|
| 151 |
-
#temperature= .1, top_p= 0.7)
|
| 152 |
-
# max tokens = change the length of the response
|
| 153 |
-
# temp = between 0-2
|
| 154 |
-
# top-p = between 0-1
|
| 155 |
-
):
|
| 156 |
-
token = message.choices[0].delta.content
|
| 157 |
-
if token:
|
| 158 |
-
response += token
|
| 159 |
-
yield response
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
with gr.Blocks(
|
| 163 |
gr.Markdown(" 🌍 Travia")
|
| 164 |
|
| 165 |
with gr.Tabs():
|
|
@@ -169,14 +171,14 @@ with gr.Blocks(theme='shivi/calm_seafoam') as app:
|
|
| 169 |
with gr.TabItem("Travel Chatbot"):
|
| 170 |
with gr.Row():
|
| 171 |
with gr.Column(scale=1):
|
|
|
|
| 172 |
destination_input = gr.Textbox(label="Travel Destination")
|
| 173 |
transportation_dropdown = gr.Dropdown(["Bus", "Plane", "Train"], label="Preferred Transportation")
|
| 174 |
-
|
| 175 |
preference_dropdown = gr.Dropdown(["Luxurious", "Cheap", "Balanced"], label="Budget Preferences")
|
| 176 |
include_checkboxes = gr.CheckboxGroup([
|
| 177 |
"Restaurant recommendations", "Hotel suggestions", "Nearby attractions", "Local tips", "Packing guides"
|
| 178 |
], label="Include in Chat")
|
| 179 |
-
minors_included = gr.Dropdown(["Yes", "No"], label = "Are there minors?")
|
| 180 |
send_button = gr.Button("Generate Guide")
|
| 181 |
|
| 182 |
with gr.Column(scale=2):
|
|
@@ -184,7 +186,7 @@ with gr.Blocks(theme='shivi/calm_seafoam') as app:
|
|
| 184 |
|
| 185 |
with gr.Column(scale=1):
|
| 186 |
gr.ChatInterface(
|
| 187 |
-
|
| 188 |
type="messages",
|
| 189 |
title="Travia",
|
| 190 |
examples=[
|
|
@@ -195,7 +197,7 @@ with gr.Blocks(theme='shivi/calm_seafoam') as app:
|
|
| 195 |
|
| 196 |
send_button.click(
|
| 197 |
respond,
|
| 198 |
-
inputs=[destination_input, transportation_dropdown,
|
| 199 |
outputs=[output_box]
|
| 200 |
)
|
| 201 |
|
|
|
|
| 45 |
]),
|
| 46 |
("2. What type of souvenir do you want to bring home?", [
|
| 47 |
("A", "A vintage print from a street artist."),
|
| 48 |
+
("B", "A quirky gadget or handmade oragami."),
|
| 49 |
("C", "A handmade bracelet and beach sarong."),
|
| 50 |
("D", "A t-shirt from a local streetwear brand."),
|
| 51 |
("E", "A flamenco fan or mosaic-tiled trinket.")
|
|
|
|
| 116 |
parsed_date = dateparser.parse(date_str, settings={'PREFER_DATES_FROM': 'future'})
|
| 117 |
return parsed_date if parsed_date else None
|
| 118 |
|
| 119 |
+
def respond(your_location, destination, transportation, date, preference, include_options):
|
| 120 |
global travel_guide_output
|
| 121 |
+
travel_date = parse_date(date)
|
| 122 |
|
| 123 |
prompt = f"""
|
| 124 |
**Travel Plan Details:**
|
| 125 |
+
- **From:** {your_location}
|
| 126 |
- **To:** {destination}
|
| 127 |
- **Transportation:** {transportation}
|
| 128 |
- **Travel Date:** {date}
|
| 129 |
- **Budget Preference:** {preference}
|
|
|
|
| 130 |
- **Additional Info:** {', '.join(include_options) if include_options else 'None'}
|
| 131 |
+
Provide a detailed travel guide based on these details.
|
|
|
|
| 132 |
"""
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
try:
|
| 135 |
+
response = model.generate_content([{"role": "user", "parts": [{"text": prompt}]}])
|
| 136 |
+
travel_guide_output = response.text
|
| 137 |
+
return response.text
|
| 138 |
+
except Exception as e:
|
| 139 |
+
return f"An error occurred: {e}"
|
| 140 |
+
|
| 141 |
+
def chatbot_respond(message, chat_history):
|
| 142 |
+
global travel_guide_output
|
| 143 |
+
if not travel_guide_output:
|
| 144 |
+
return "No travel guide has been generated yet. Please enter your travel details first."
|
| 145 |
|
| 146 |
+
prompt = f"""
|
| 147 |
+
You are an AI travel assistant. The user has already generated a travel guide. Use the following details to assist them:
|
| 148 |
+
|
| 149 |
+
{travel_guide_output}
|
| 150 |
+
|
| 151 |
+
If the user asks a question related to their trip, provide an answer based on this guide.
|
| 152 |
+
If the user asks general travel questions, respond accordingly.
|
| 153 |
+
If they make casual conversation, respond naturally.
|
| 154 |
+
|
| 155 |
+
User's message: {message}
|
| 156 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
+
try:
|
| 159 |
+
response = model.generate_content([{"role": "user", "parts": [{"text": prompt}]}])
|
| 160 |
+
return response.text
|
| 161 |
+
except Exception as e:
|
| 162 |
+
return f"An error occurred: {e}"
|
| 163 |
|
| 164 |
+
with gr.Blocks() as app:
|
| 165 |
gr.Markdown(" 🌍 Travia")
|
| 166 |
|
| 167 |
with gr.Tabs():
|
|
|
|
| 171 |
with gr.TabItem("Travel Chatbot"):
|
| 172 |
with gr.Row():
|
| 173 |
with gr.Column(scale=1):
|
| 174 |
+
your_location_input = gr.Textbox(label="Your Current Location")
|
| 175 |
destination_input = gr.Textbox(label="Travel Destination")
|
| 176 |
transportation_dropdown = gr.Dropdown(["Bus", "Plane", "Train"], label="Preferred Transportation")
|
| 177 |
+
date_input = gr.Textbox(label="Travel Date (e.g., tomorrow, March 15)")
|
| 178 |
preference_dropdown = gr.Dropdown(["Luxurious", "Cheap", "Balanced"], label="Budget Preferences")
|
| 179 |
include_checkboxes = gr.CheckboxGroup([
|
| 180 |
"Restaurant recommendations", "Hotel suggestions", "Nearby attractions", "Local tips", "Packing guides"
|
| 181 |
], label="Include in Chat")
|
|
|
|
| 182 |
send_button = gr.Button("Generate Guide")
|
| 183 |
|
| 184 |
with gr.Column(scale=2):
|
|
|
|
| 186 |
|
| 187 |
with gr.Column(scale=1):
|
| 188 |
gr.ChatInterface(
|
| 189 |
+
respond,
|
| 190 |
type="messages",
|
| 191 |
title="Travia",
|
| 192 |
examples=[
|
|
|
|
| 197 |
|
| 198 |
send_button.click(
|
| 199 |
respond,
|
| 200 |
+
inputs=[your_location_input, destination_input, transportation_dropdown, date_input, preference_dropdown, include_checkboxes],
|
| 201 |
outputs=[output_box]
|
| 202 |
)
|
| 203 |
|