CR commited on
Update app.py
Browse filestrying to get the json right
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,16 @@ 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 |
-
|
| 27 |
-
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
return f"Error fetching data for location '{location}': {str(e)}"
|
| 30 |
try:
|
| 31 |
# Then we use that to get the current temperature in Fahrenheit
|
| 32 |
current_data = httpx.get('https://api.openweathermap.org/data/3.0/onecall?lat={latitude}&lon={longitude}&units={imperial}&appid={OpenWeather_API_key}')
|
| 33 |
-
|
|
|
|
| 34 |
return f"The current temperature in {location} is {temperature} degrees Fahrenheit."
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching temperature for location '{location}': {str(e)}"
|
|
|
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
import os
|
| 9 |
+
import json
|
| 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 |
+
data = geocoding_data.json()
|
| 28 |
+
latitude = data[0]["lat"]
|
| 29 |
+
longitude = data[0]["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 |
+
data = current_data.json()
|
| 36 |
+
temperature = data["current"]["temp"]
|
| 37 |
return f"The current temperature in {location} is {temperature} degrees Fahrenheit."
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error fetching temperature for location '{location}': {str(e)}"
|