Spaces:
Sleeping
Sleeping
Update app.py
Browse files132 unmodified lines1331341351361371381393 unmodified lines1431441451461471481495 unmodified lines1551561571581591601611621631641651661671681691701711721731741751761771 unmodified line179180181182183184132 unmodified linesdef get_best_season(location):"""AI-powered function to recommend the best season or general weather for any location."""if not location.strip() or location.lower() == "any destination":return " Best season info is available for specific locations only."prompt = (f"Suggest the best season or time of year to visit {location} based on weather and tourism. "3 unmodified linestry:print(f"🔍 Calling Groq API for location: {location}")response = client.chat.completions.create(model="openai/gpt-oss-20B", # or openai/gpt-oss-20b if supportedmessages=[{"role": "system", "content": "You are a travel expert."},{"role": "user", "content": prompt}5 unmodified lines)print("✅ Received response from API.")# Extract content safely# ✅ Extract content safely (for both message-based and text-based completions)if hasattr(response.choices[0], "message") and hasattr(response.choices[0].message, "content"):season_text = response.choices[0].message.contentelif "message" in response.choices[0] and "content" in response.choices[0]["message"]:season_text = response.choices[0]["message"]["content"]elif hasattr(response.choices[0], "text"):season_text = response.choices[0].textelse:season_text = "(No text returned)"except Exception as e:print("⚠️ Parsing error:", e)season_text = "(Error extracting content)"except Exception as e:print("⚠️ Full error while getting season:\n")traceback.print_exc()return "🌤️ Unable to determine the best season right now."1 unmodified linedef generate_pdf(itinerary_text):if not itinerary_text.strip():return None, gr.update(visible=False)132 unmodified lines1331341351361371381393 unmodified lines1431441451461471481495 unmodified lines1551561571581591601611621631641651661671681691701711721731741751 unmodified line177178179180181182183132 unmodified linesdef get_best_season(location):"""AI-powered function to recommend the best season or general weather for any location."""if not location.strip() or location.lower() == "any destination":return "🌤️ Best season info is available for specific locations only."prompt = (f"Suggest the best season or time of year to visit {location} based on weather and tourism. "3 unmodified linestry:print(f"🔍 Calling Groq API for location: {location}")response = client.chat.completions.create(model="openai/gpt-oss-20B", # ✅ correct model namemessages=[{"role": "system", "content": "You are a travel expert."},{"role": "user", "content": prompt}5 unmodified lines)print("✅ Received response from API.")# ✅ Extract content safely (supports both message-based & text-based responses)if hasattr(response.choices[0], "message") and hasattr(response.choices[0].message, "content"):season_text = response.choices[0].message.contentelif "message" in response.choices[0] and "content" in response.choices[0]["message"]:season_text = response.choices[0]["message"]["content"]elif hasattr(response.choices[0], "text"):season_text = response.choices[0].textelse:season_text = "(No text returned)"print("🧠 AI raw response:", season_text)return f"🌤️ {season_text.strip()}"except Exception as e:import tracebackprint("⚠️ Full error while getting season:\n")traceback.print_exc()return "🌤️ Unable to determine the best season right now."1 unmodified linedef generate_pdf(itinerary_text):if not itinerary_text.strip():return None, gr.update(visible=False)
app.py+15-16