CR commited on
Update app.py
Browse filesadded a second try else and some logging for debug
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import pytz
|
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
@@ -23,14 +24,18 @@ def get_current_temperature(location: str)-> str: #it's import to specify the re
|
|
| 23 |
try:
|
| 24 |
# First we get the geocoding data to get the latitude and longitude of a location
|
| 25 |
geocoding_data = httpx.get('http://api.openweathermap.org/geo/1.0/direct?q={location}&limit=1&appid={OpenWeather_API_key}')
|
|
|
|
| 26 |
latitude = geocoding_data.lat
|
| 27 |
longitude = geocoding_data.lon
|
|
|
|
|
|
|
|
|
|
| 28 |
# Then we use that to get the current temperature in Fahrenheit
|
| 29 |
current_data = httpx.get('https://api.openweathermap.org/data/3.0/onecall?lat={latitude}&lon={longitude}&units={imperial}&appid={OpenWeather_API_key}')
|
| 30 |
temperature = current_data.current.temp
|
| 31 |
return f"The current temperature in {location} is {temperature} degrees Fahrenheit."
|
| 32 |
except Exception as e:
|
| 33 |
-
return f"Error fetching
|
| 34 |
|
| 35 |
|
| 36 |
@tool
|
|
|
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
import os
|
| 9 |
+
from loguru import logger
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
|
|
|
| 24 |
try:
|
| 25 |
# First we get the geocoding data to get the latitude and longitude of a location
|
| 26 |
geocoding_data = httpx.get('http://api.openweathermap.org/geo/1.0/direct?q={location}&limit=1&appid={OpenWeather_API_key}')
|
| 27 |
+
logger.info(f"geocoding_data = '{geocoding_data}'")
|
| 28 |
latitude = geocoding_data.lat
|
| 29 |
longitude = geocoding_data.lon
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error fetching data for location '{location}': {str(e)}"
|
| 32 |
+
try:
|
| 33 |
# Then we use that to get the current temperature in Fahrenheit
|
| 34 |
current_data = httpx.get('https://api.openweathermap.org/data/3.0/onecall?lat={latitude}&lon={longitude}&units={imperial}&appid={OpenWeather_API_key}')
|
| 35 |
temperature = current_data.current.temp
|
| 36 |
return f"The current temperature in {location} is {temperature} degrees Fahrenheit."
|
| 37 |
except Exception as e:
|
| 38 |
+
return f"Error fetching temperature for location '{location}': {str(e)}"
|
| 39 |
|
| 40 |
|
| 41 |
@tool
|