Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -110,6 +110,42 @@ def generate_itinerary(mood, location, budget, days):
|
|
| 110 |
|
| 111 |
return itinerary_text, image_path, map_html
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
def generate_pdf(itinerary_text):
|
| 114 |
if not itinerary_text.strip():
|
| 115 |
return None, gr.update(visible=False)
|
|
|
|
| 110 |
|
| 111 |
return itinerary_text, image_path, map_html
|
| 112 |
|
| 113 |
+
def get_best_season(location):
|
| 114 |
+
"""AI-powered function to recommend the best season to visit any city, state, or country."""
|
| 115 |
+
if not location.strip() or location.lower() == "any destination":
|
| 116 |
+
return "🌤️ Best season info is available for specific locations only."
|
| 117 |
+
|
| 118 |
+
prompt = (
|
| 119 |
+
f"Based on weather, tourism, and festivals, suggest the best season or months to visit {location}. "
|
| 120 |
+
f"Explain briefly in 25 words or less."
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
response = client.chat.completions.create(
|
| 125 |
+
model="openai/gpt-oss-20b", # You can replace this with any working model, e.g. "llama-3.1-8b"
|
| 126 |
+
messages=[
|
| 127 |
+
{"role": "system", "content": "You are an expert travel advisor."},
|
| 128 |
+
{"role": "user", "content": prompt}
|
| 129 |
+
],
|
| 130 |
+
temperature=0.7,
|
| 131 |
+
max_tokens=120,
|
| 132 |
+
top_p=1,
|
| 133 |
+
stream=False
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
# Safely extract the content depending on SDK format
|
| 137 |
+
if hasattr(response.choices[0].message, "content"):
|
| 138 |
+
season_text = response.choices[0].message.content
|
| 139 |
+
else:
|
| 140 |
+
season_text = response.choices[0].message["content"]
|
| 141 |
+
|
| 142 |
+
return f"🌤️ {season_text.strip()}"
|
| 143 |
+
|
| 144 |
+
except Exception as e:
|
| 145 |
+
print("⚠️ Error getting season:", e)
|
| 146 |
+
return "🌤️ Unable to determine the best season right now."
|
| 147 |
+
|
| 148 |
+
|
| 149 |
def generate_pdf(itinerary_text):
|
| 150 |
if not itinerary_text.strip():
|
| 151 |
return None, gr.update(visible=False)
|