Infinity-1995 commited on
Commit
a4c360c
·
verified ·
1 Parent(s): 8de9c47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -37,7 +37,6 @@ TRAVELLER_TYPES = [
37
  "Any"
38
  ]
39
 
40
-
41
  MOOD_IMAGES = {
42
  "Adventure": "images/adventure.png",
43
  "Relaxing": "images/relaxing.png",
@@ -91,21 +90,14 @@ def generate_itinerary(mood, location, budget, days, traveller_type, current_loc
91
  location_text = location if location.strip() != "" else "any destination"
92
  from_text = current_location.strip() if current_location.strip() != "" else "your city"
93
 
94
- prompt = (
95
- f"Create a {days}-day travel itinerary from {from_text} to {location_text}. "
96
- f"The traveler’s mood is {mood_text}, traveller type is {traveller_text}, "
97
- f"and the budget is {budget_text}. "
98
- f"Include daily activities, key landmarks, and meal or cultural suggestions. "
99
- f"Use Markdown formatting with **bold headings** for days and time slots."
100
- )
101
 
102
-
103
- prompt = (
104
- f"Create a {days}-day travel itinerary to {location_text}. "
105
- f"The mood of the traveler is {mood_text} and the budget is {budget_text}. "
106
- f"Use Markdown formatting with **bold headings** for days and time slots."
107
- )
108
-
109
  completion = client.chat.completions.create(
110
  model="gemma2-9b-it",
111
  messages=[
@@ -117,10 +109,9 @@ prompt = (
117
  top_p=1,
118
  stream=False
119
  )
120
-
121
  itinerary_text = completion.choices[0].message.content
122
  image_path = os.path.abspath(MOOD_IMAGES.get(mood, MOOD_IMAGES["Any"]))
123
-
124
  map_html = extract_places_and_map(itinerary_text, city_context=location_text if location_text.lower() != "any destination" else None)
125
 
126
  return itinerary_text, image_path, map_html
@@ -157,6 +148,7 @@ def generate_pdf(itinerary_text):
157
  doc.build(story)
158
 
159
  return temp_path, gr.update(visible=True)
 
160
  # ---------------------- UI ----------------------
161
  with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")) as demo:
162
 
@@ -251,7 +243,6 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")
251
  traveller_type = gr.Dropdown(TRAVELLER_TYPES, label="Traveller Type", value="Any")
252
  current_location = gr.Textbox(label="Current Location (From)", placeholder="e.g., Dubai, London (optional)")
253
 
254
-
255
  with gr.Row():
256
  budget = gr.Dropdown(["Low", "Medium", "High", "Any"], label="Budget", value="Any")
257
  days = gr.Slider(1, 10, value=5, step=1, label="Days")
@@ -282,7 +273,6 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")
282
  show_progress=True
283
  )
284
 
285
-
286
  download_btn.click(
287
  generate_pdf,
288
  inputs=[itinerary_output],
@@ -290,3 +280,4 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")
290
  )
291
 
292
  demo.launch()
 
 
37
  "Any"
38
  ]
39
 
 
40
  MOOD_IMAGES = {
41
  "Adventure": "images/adventure.png",
42
  "Relaxing": "images/relaxing.png",
 
90
  location_text = location if location.strip() != "" else "any destination"
91
  from_text = current_location.strip() if current_location.strip() != "" else "your city"
92
 
93
+ prompt = (
94
+ f"Create a {days}-day travel itinerary from {from_text} to {location_text}. "
95
+ f"The traveler’s mood is {mood_text}, traveller type is {traveller_text}, "
96
+ f"and the budget is {budget_text}. "
97
+ f"Include daily activities, key landmarks, and meal or cultural suggestions. "
98
+ f"Use Markdown formatting with **bold headings** for days and time slots."
99
+ )
100
 
 
 
 
 
 
 
 
101
  completion = client.chat.completions.create(
102
  model="gemma2-9b-it",
103
  messages=[
 
109
  top_p=1,
110
  stream=False
111
  )
112
+
113
  itinerary_text = completion.choices[0].message.content
114
  image_path = os.path.abspath(MOOD_IMAGES.get(mood, MOOD_IMAGES["Any"]))
 
115
  map_html = extract_places_and_map(itinerary_text, city_context=location_text if location_text.lower() != "any destination" else None)
116
 
117
  return itinerary_text, image_path, map_html
 
148
  doc.build(story)
149
 
150
  return temp_path, gr.update(visible=True)
151
+
152
  # ---------------------- UI ----------------------
153
  with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")) as demo:
154
 
 
243
  traveller_type = gr.Dropdown(TRAVELLER_TYPES, label="Traveller Type", value="Any")
244
  current_location = gr.Textbox(label="Current Location (From)", placeholder="e.g., Dubai, London (optional)")
245
 
 
246
  with gr.Row():
247
  budget = gr.Dropdown(["Low", "Medium", "High", "Any"], label="Budget", value="Any")
248
  days = gr.Slider(1, 10, value=5, step=1, label="Days")
 
273
  show_progress=True
274
  )
275
 
 
276
  download_btn.click(
277
  generate_pdf,
278
  inputs=[itinerary_output],
 
280
  )
281
 
282
  demo.launch()
283
+