Infinity-1995 commited on
Commit
38ce6d2
·
verified ·
1 Parent(s): 6b80252

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -133,7 +133,7 @@ def generate_itinerary(mood, location, budget, days):
133
  def get_best_season(location):
134
  """AI-powered function to recommend the best season or general weather for any location."""
135
  if not location.strip() or location.lower() == "any destination":
136
- return " Best season info is available for specific locations only."
137
 
138
  prompt = (
139
  f"Suggest the best season or time of year to visit {location} based on weather and tourism. "
@@ -143,7 +143,7 @@ def get_best_season(location):
143
  try:
144
  print(f"🔍 Calling Groq API for location: {location}")
145
  response = client.chat.completions.create(
146
- model="openai/gpt-oss-20B", # or openai/gpt-oss-20b if supported
147
  messages=[
148
  {"role": "system", "content": "You are a travel expert."},
149
  {"role": "user", "content": prompt}
@@ -155,23 +155,21 @@ def get_best_season(location):
155
  )
156
  print("✅ Received response from API.")
157
 
158
- # Extract content safely
159
- # ✅ Extract content safely (for both message-based and text-based completions)
160
-
161
- if hasattr(response.choices[0], "message") and hasattr(response.choices[0].message, "content"):
162
- season_text = response.choices[0].message.content
163
- elif "message" in response.choices[0] and "content" in response.choices[0]["message"]:
164
- season_text = response.choices[0]["message"]["content"]
165
- elif hasattr(response.choices[0], "text"):
166
- season_text = response.choices[0].text
167
- else:
168
- season_text = "(No text returned)"
169
- except Exception as e:
170
- print("⚠️ Parsing error:", e)
171
- season_text = "(Error extracting content)"
172
 
 
 
173
 
174
  except Exception as e:
 
175
  print("⚠️ Full error while getting season:\n")
176
  traceback.print_exc()
177
  return "🌤️ Unable to determine the best season right now."
@@ -179,6 +177,7 @@ def get_best_season(location):
179
 
180
 
181
 
 
182
  def generate_pdf(itinerary_text):
183
  if not itinerary_text.strip():
184
  return None, gr.update(visible=False)
 
133
  def get_best_season(location):
134
  """AI-powered function to recommend the best season or general weather for any location."""
135
  if not location.strip() or location.lower() == "any destination":
136
+ return "🌤️ Best season info is available for specific locations only."
137
 
138
  prompt = (
139
  f"Suggest the best season or time of year to visit {location} based on weather and tourism. "
 
143
  try:
144
  print(f"🔍 Calling Groq API for location: {location}")
145
  response = client.chat.completions.create(
146
+ model="openai/gpt-oss-20B", # correct model name
147
  messages=[
148
  {"role": "system", "content": "You are a travel expert."},
149
  {"role": "user", "content": prompt}
 
155
  )
156
  print("✅ Received response from API.")
157
 
158
+ # Extract content safely (supports both message-based & text-based responses)
159
+ if hasattr(response.choices[0], "message") and hasattr(response.choices[0].message, "content"):
160
+ season_text = response.choices[0].message.content
161
+ elif "message" in response.choices[0] and "content" in response.choices[0]["message"]:
162
+ season_text = response.choices[0]["message"]["content"]
163
+ elif hasattr(response.choices[0], "text"):
164
+ season_text = response.choices[0].text
165
+ else:
166
+ season_text = "(No text returned)"
 
 
 
 
 
167
 
168
+ print("🧠 AI raw response:", season_text)
169
+ return f"🌤️ {season_text.strip()}"
170
 
171
  except Exception as e:
172
+ import traceback
173
  print("⚠️ Full error while getting season:\n")
174
  traceback.print_exc()
175
  return "🌤️ Unable to determine the best season right now."
 
177
 
178
 
179
 
180
+
181
  def generate_pdf(itinerary_text):
182
  if not itinerary_text.strip():
183
  return None, gr.update(visible=False)