Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -225,7 +225,6 @@ def generate_packing_list(destination: str, weather_summary: str, trip_days: int
|
|
| 225 |
"\n💡 Pro tip: Roll clothes to save space. Pack one versatile outfit per day + 1 extra day buffer."
|
| 226 |
)
|
| 227 |
|
| 228 |
-
|
| 229 |
@tool
|
| 230 |
def build_itinerary(destination: str, attractions: str, budget_local: float, days: int) -> str:
|
| 231 |
"""
|
|
@@ -270,7 +269,7 @@ def build_itinerary(destination: str, attractions: str, budget_local: float, day
|
|
| 270 |
@tool
|
| 271 |
def generate_travel_images(destination: str) -> str:
|
| 272 |
"""
|
| 273 |
-
Generate two realistic placeholder image URLs for the destination using
|
| 274 |
|
| 275 |
Args:
|
| 276 |
destination: Destination city name (e.g., "Lisbon")
|
|
@@ -279,21 +278,23 @@ def generate_travel_images(destination: str) -> str:
|
|
| 279 |
JSON-formatted string containing two image URLs with keys "landmark_image" and "street_scene_image"
|
| 280 |
"""
|
| 281 |
try:
|
| 282 |
-
#
|
| 283 |
-
|
|
|
|
|
|
|
| 284 |
|
| 285 |
-
landmark_url = f"https://
|
| 286 |
-
street_url = f"https://
|
| 287 |
|
| 288 |
return json.dumps({
|
| 289 |
"landmark_image": landmark_url,
|
| 290 |
"street_scene_image": street_url
|
| 291 |
})
|
| 292 |
except Exception as e:
|
| 293 |
-
# Fallback to generic
|
| 294 |
return json.dumps({
|
| 295 |
-
"landmark_image": "https://
|
| 296 |
-
"street_scene_image": "https://
|
| 297 |
})
|
| 298 |
|
| 299 |
|
|
@@ -329,56 +330,58 @@ def assemble_catalogue(
|
|
| 329 |
# Parse image URLs
|
| 330 |
try:
|
| 331 |
images = json.loads(image_urls_json)
|
| 332 |
-
img1 = images.get("landmark_image", "https://
|
| 333 |
-
img2 = images.get("street_scene_image", "https://
|
| 334 |
except:
|
| 335 |
-
img1 = "https://
|
| 336 |
-
img2 = "https://
|
| 337 |
|
| 338 |
# Count days in itinerary
|
| 339 |
day_count = len(re.findall(r'DAY\s+\d+', itinerary))
|
| 340 |
|
| 341 |
-
|
|
|
|
|
|
|
| 342 |
*Planned from {origin} • {dates} • {budget_summary}*
|
| 343 |
|
| 344 |
---
|
| 345 |
|
| 346 |
## ⏰ Time Zone Adjustment
|
|
|
|
| 347 |
{timezone_info}
|
| 348 |
|
| 349 |
---
|
| 350 |
|
| 351 |
## 🌤️ Weather Forecast & Packing Guidance
|
|
|
|
| 352 |
{weather}
|
| 353 |
|
| 354 |
---
|
| 355 |
|
| 356 |
## 🗓️ Your Personalized {day_count}-Day Itinerary
|
|
|
|
| 357 |
{itinerary}
|
| 358 |
|
| 359 |
---
|
| 360 |
|
| 361 |
## 🎒 Complete Packing Checklist
|
|
|
|
| 362 |
{packing_list}
|
| 363 |
|
| 364 |
---
|
| 365 |
|
| 366 |
## 📸 Visual Inspiration
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
<div style="flex: 1; text-align: center;">
|
| 374 |
-
<img src="{img2}" alt="{destination} street scene" style="max-width: 100%; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
|
| 375 |
-
<p><em>Vibrant local atmosphere</em></p>
|
| 376 |
-
</div>
|
| 377 |
-
</div>
|
| 378 |
|
| 379 |
---
|
| 380 |
|
| 381 |
> 💡 **Travel Pro Tips**
|
|
|
|
| 382 |
> • Download offline Google Maps before departure
|
| 383 |
> • Learn 5 basic phrases in the local language
|
| 384 |
> • Keep digital copies of passport/insurance in cloud storage
|
|
@@ -389,6 +392,7 @@ def assemble_catalogue(
|
|
| 389 |
|
| 390 |
**Happy Travels! ✈️**
|
| 391 |
"""
|
|
|
|
| 392 |
|
| 393 |
|
| 394 |
# ======================
|
|
|
|
| 225 |
"\n💡 Pro tip: Roll clothes to save space. Pack one versatile outfit per day + 1 extra day buffer."
|
| 226 |
)
|
| 227 |
|
|
|
|
| 228 |
@tool
|
| 229 |
def build_itinerary(destination: str, attractions: str, budget_local: float, days: int) -> str:
|
| 230 |
"""
|
|
|
|
| 269 |
@tool
|
| 270 |
def generate_travel_images(destination: str) -> str:
|
| 271 |
"""
|
| 272 |
+
Generate two realistic placeholder image URLs for the destination using Picsum Photos API.
|
| 273 |
|
| 274 |
Args:
|
| 275 |
destination: Destination city name (e.g., "Lisbon")
|
|
|
|
| 278 |
JSON-formatted string containing two image URLs with keys "landmark_image" and "street_scene_image"
|
| 279 |
"""
|
| 280 |
try:
|
| 281 |
+
# Use Lorem Picsum for reliable random images with unique seeds
|
| 282 |
+
import hashlib
|
| 283 |
+
seed1 = int(hashlib.md5(f"{destination}-landmark".encode()).hexdigest()[:8], 16) % 1000
|
| 284 |
+
seed2 = int(hashlib.md5(f"{destination}-street".encode()).hexdigest()[:8], 16) % 1000
|
| 285 |
|
| 286 |
+
landmark_url = f"https://picsum.photos/seed/{seed1}/800/600"
|
| 287 |
+
street_url = f"https://picsum.photos/seed/{seed2}/800/600"
|
| 288 |
|
| 289 |
return json.dumps({
|
| 290 |
"landmark_image": landmark_url,
|
| 291 |
"street_scene_image": street_url
|
| 292 |
})
|
| 293 |
except Exception as e:
|
| 294 |
+
# Fallback to generic images
|
| 295 |
return json.dumps({
|
| 296 |
+
"landmark_image": "https://picsum.photos/800/600?random=1",
|
| 297 |
+
"street_scene_image": "https://picsum.photos/800/600?random=2"
|
| 298 |
})
|
| 299 |
|
| 300 |
|
|
|
|
| 330 |
# Parse image URLs
|
| 331 |
try:
|
| 332 |
images = json.loads(image_urls_json)
|
| 333 |
+
img1 = images.get("landmark_image", "https://picsum.photos/800/600?random=1")
|
| 334 |
+
img2 = images.get("street_scene_image", "https://picsum.photos/800/600?random=2")
|
| 335 |
except:
|
| 336 |
+
img1 = "https://picsum.photos/800/600?random=1"
|
| 337 |
+
img2 = "https://picsum.photos/800/600?random=2"
|
| 338 |
|
| 339 |
# Count days in itinerary
|
| 340 |
day_count = len(re.findall(r'DAY\s+\d+', itinerary))
|
| 341 |
|
| 342 |
+
# Build catalogue with proper Gradio-compatible Markdown
|
| 343 |
+
catalogue = f"""# 🌍 {destination} Travel Catalogue
|
| 344 |
+
|
| 345 |
*Planned from {origin} • {dates} • {budget_summary}*
|
| 346 |
|
| 347 |
---
|
| 348 |
|
| 349 |
## ⏰ Time Zone Adjustment
|
| 350 |
+
|
| 351 |
{timezone_info}
|
| 352 |
|
| 353 |
---
|
| 354 |
|
| 355 |
## 🌤️ Weather Forecast & Packing Guidance
|
| 356 |
+
|
| 357 |
{weather}
|
| 358 |
|
| 359 |
---
|
| 360 |
|
| 361 |
## 🗓️ Your Personalized {day_count}-Day Itinerary
|
| 362 |
+
|
| 363 |
{itinerary}
|
| 364 |
|
| 365 |
---
|
| 366 |
|
| 367 |
## 🎒 Complete Packing Checklist
|
| 368 |
+
|
| 369 |
{packing_list}
|
| 370 |
|
| 371 |
---
|
| 372 |
|
| 373 |
## 📸 Visual Inspiration
|
| 374 |
|
| 375 |
+

|
| 376 |
+
*Iconic {destination} landmark*
|
| 377 |
+
|
| 378 |
+

|
| 379 |
+
*Vibrant local atmosphere*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
---
|
| 382 |
|
| 383 |
> 💡 **Travel Pro Tips**
|
| 384 |
+
>
|
| 385 |
> • Download offline Google Maps before departure
|
| 386 |
> • Learn 5 basic phrases in the local language
|
| 387 |
> • Keep digital copies of passport/insurance in cloud storage
|
|
|
|
| 392 |
|
| 393 |
**Happy Travels! ✈️**
|
| 394 |
"""
|
| 395 |
+
return catalogue
|
| 396 |
|
| 397 |
|
| 398 |
# ======================
|