Infinity-1995 commited on
Commit
a542c25
·
verified ·
1 Parent(s): 3e7ec50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -39
app.py CHANGED
@@ -94,12 +94,13 @@ def generate_itinerary(mood, location, budget, days):
94
  )
95
 
96
  # 🧩 Generate itinerary
97
- completion = client.chat.completions.create(
98
  model="openai/gpt-oss-20B", # Use gemma or gpt-oss if this doesn't work
99
  messages=[
100
  {"role": "system", "content": "You are an expert travel planner."},
101
  {"role": "user", "content": prompt}
102
  ],
 
103
  temperature=0.8,
104
  max_tokens=2800, # enough for multi-day itineraries
105
  top_p=1,
@@ -143,48 +144,24 @@ def get_best_season(location):
143
  try:
144
  print(f"🔍 Calling Groq API for location: {location}")
145
 
146
- # Try chat model first
147
- try:
148
- response = client.chat.completions.create(
149
- model="gemma2-9b-it", # ✅ works with Groq
150
- messages=[
151
- {"role": "system", "content": "You are a travel expert."},
152
- {"role": "user", "content": prompt}
153
- ],
154
- temperature=0.7,
155
- max_completion_tokens=120,
156
- top_p=1,
157
- stream=False
158
- )
159
-
160
- if hasattr(response.choices[0].message, "content"):
161
- season_text = response.choices[0].message.content
162
- else:
163
- season_text = response.choices[0].message["content"]
164
-
165
- except Exception as e:
166
- # ✅ Fallback for models that don’t support chat.completions
167
- print("⚠️ Chat completion failed, trying text generation fallback...")
168
- completion = client.completions.create(
169
- model="gemma2-9b-it",
170
- prompt=prompt,
171
- max_tokens=120,
172
- temperature=0.7,
173
- top_p=1
174
- )
175
- season_text = completion.choices[0].text
176
-
177
- print("✅ Received response from API.")
178
- print("🧠 AI raw response:", season_text)
179
-
180
- if not season_text.strip():
181
  return "🌤️ Season info not available right now."
182
 
183
- return f"🌤️ {season_text.strip()}"
184
 
185
  except Exception as e:
186
- print("⚠️ Full error while getting season:\n")
187
- traceback.print_exc()
188
  return "🌤️ Unable to determine the best season right now."
189
 
190
 
@@ -192,6 +169,7 @@ def get_best_season(location):
192
 
193
 
194
 
 
195
  def generate_pdf(itinerary_text):
196
  if not itinerary_text.strip():
197
  return None, gr.update(visible=False)
 
94
  )
95
 
96
  # 🧩 Generate itinerary
97
+ completion = client.response.create(
98
  model="openai/gpt-oss-20B", # Use gemma or gpt-oss if this doesn't work
99
  messages=[
100
  {"role": "system", "content": "You are an expert travel planner."},
101
  {"role": "user", "content": prompt}
102
  ],
103
+ input=prompt,
104
  temperature=0.8,
105
  max_tokens=2800, # enough for multi-day itineraries
106
  top_p=1,
 
144
  try:
145
  print(f"🔍 Calling Groq API for location: {location}")
146
 
147
+ # Use the responses.create() method with gpt-oss-20b
148
+ response = client.responses.create(
149
+ model="openai/gpt-oss-20b",
150
+ input=prompt,
151
+ temperature=0.7,
152
+ max_output_tokens=120
153
+ )
154
+
155
+ # Access the generated text
156
+ season_text = response.output_text.strip() if hasattr(response, "output_text") else str(response)
157
+
158
+ if not season_text:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  return "🌤️ Season info not available right now."
160
 
161
+ return f"🌤️ {season_text}"
162
 
163
  except Exception as e:
164
+ print("⚠️ Error while getting season:\n", e)
 
165
  return "🌤️ Unable to determine the best season right now."
166
 
167
 
 
169
 
170
 
171
 
172
+
173
  def generate_pdf(itinerary_text):
174
  if not itinerary_text.strip():
175
  return None, gr.update(visible=False)