Infinity-1995 commited on
Commit
5657e3c
·
verified ·
1 Parent(s): 5040c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -126,19 +126,16 @@ def generate_itinerary(mood, location, budget, days):
126
  return "🌤️ Unable to generate itinerary at this time.", None, None
127
 
128
  def get_best_season(location):
129
- """AI-powered function to recommend the best season or general weather for any location."""
130
- if not location.strip() or location.lower() == "any destination":
131
  return "🌤️ Best season info is available for specific locations only."
132
-
133
  prompt = (
134
- f"Suggest the best season or time of year to visit {location} based on weather and tourism. "
135
- f"Keep it short and under 25 words."
136
  )
137
 
138
  try:
139
- print(f"🔍 Calling Groq API for location: {location}")
140
-
141
- # Use chat.completions.create() method with gpt-oss-20b
142
  response = client.chat.completions.create(
143
  messages=[
144
  {"role": "system", "content": "You are a travel expert."},
@@ -150,17 +147,19 @@ def get_best_season(location):
150
  top_p=1
151
  )
152
 
153
- season_text = response.choices[0].message.content.strip()
 
 
 
154
 
155
  if not season_text:
156
- return "🌤️ Season info not available right now."
157
-
158
  return f"🌤️ {season_text}"
159
 
160
  except Exception as e:
161
  print("⚠️ Error while getting season:\n", e)
162
- return "🌤️ Unable to determine the best season right now."
163
-
164
 
165
  def generate_pdf(itinerary_text):
166
  if not itinerary_text.strip():
 
126
  return "🌤️ Unable to generate itinerary at this time.", None, None
127
 
128
  def get_best_season(location):
129
+ location_clean = location.strip()
130
+ if not location_clean or location_clean.lower() == "any destination":
131
  return "🌤️ Best season info is available for specific locations only."
132
+
133
  prompt = (
134
+ f"You are a travel expert. Suggest the best season or months to visit {location_clean}, "
135
+ f"considering weather, tourist crowds, and local events. Keep it 1-2 sentences."
136
  )
137
 
138
  try:
 
 
 
139
  response = client.chat.completions.create(
140
  messages=[
141
  {"role": "system", "content": "You are a travel expert."},
 
147
  top_p=1
148
  )
149
 
150
+ season_text = (
151
+ getattr(response.choices[0].message, "content", "")
152
+ or getattr(response.choices[0], "text", "")
153
+ ).strip()
154
 
155
  if not season_text:
156
+ # fallback if model returns nothing
157
+ return SEASON_FALLBACK.get(location_clean, "🌤️ Season info not available right now.")
158
  return f"🌤️ {season_text}"
159
 
160
  except Exception as e:
161
  print("⚠️ Error while getting season:\n", e)
162
+ return SEASON_FALLBACK.get(location_clean, "🌤️ Unable to determine the best season right now.")
 
163
 
164
  def generate_pdf(itinerary_text):
165
  if not itinerary_text.strip():