Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -156,12 +156,20 @@ def get_best_season(location):
|
|
| 156 |
print("✅ Received response from API.")
|
| 157 |
|
| 158 |
# Extract content safely
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
return f"🌤️ {season_text.strip()}"
|
| 165 |
|
| 166 |
except Exception as e:
|
| 167 |
print("⚠️ Full error while getting season:\n")
|
|
|
|
| 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")
|