Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,10 +13,10 @@ def get_current_weather(place: str)-> str: #it's import to specify the return ty
|
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that fetches the current weather of a particular place
|
| 15 |
Args:
|
| 16 |
-
place: A string representing a valid place (e.g., 'London/
|
| 17 |
"""
|
| 18 |
-
api_key = ""
|
| 19 |
-
url = ""
|
| 20 |
params = {
|
| 21 |
"city": place
|
| 22 |
"api_id": api_key
|
|
@@ -25,8 +25,25 @@ def get_current_weather(place: str)-> str: #it's import to specify the return ty
|
|
| 25 |
|
| 26 |
try:
|
| 27 |
response = requests.get(url, params=params)
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
except Exception as e:
|
| 31 |
return f"Error fetching weather data for '{place}': {str(e)}"
|
| 32 |
|
|
|
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that fetches the current weather of a particular place
|
| 15 |
Args:
|
| 16 |
+
place: A string representing a valid place (e.g., 'London/Paris')
|
| 17 |
"""
|
| 18 |
+
api_key = "Weather_Token"
|
| 19 |
+
url = "https://api.openweathermap.org/data/2.5/weather"
|
| 20 |
params = {
|
| 21 |
"city": place
|
| 22 |
"api_id": api_key
|
|
|
|
| 25 |
|
| 26 |
try:
|
| 27 |
response = requests.get(url, params=params)
|
| 28 |
+
data = response.json()
|
| 29 |
+
|
| 30 |
+
# Check if the request was successful
|
| 31 |
+
if response.status_code == 200:
|
| 32 |
+
weather_desc = data["weather"][0]["description"]
|
| 33 |
+
temperature = data["main"]["temp"]
|
| 34 |
+
humidity = data["main"]["humidity"]
|
| 35 |
+
wind_speed = data["wind"]["speed"]
|
| 36 |
+
|
| 37 |
+
# Display the results
|
| 38 |
+
return (
|
| 39 |
+
f"Weather in {place}:\n"
|
| 40 |
+
f"- Condition: {weather_desc}\n"
|
| 41 |
+
f"- Temperature: {temperature}°C\n"
|
| 42 |
+
f"- Humidity: {humidity}%\n"
|
| 43 |
+
f"- Wind Speed: {wind_speed} m/s"
|
| 44 |
+
)
|
| 45 |
+
else:
|
| 46 |
+
return f"Error: {data['message']}"
|
| 47 |
except Exception as e:
|
| 48 |
return f"Error fetching weather data for '{place}': {str(e)}"
|
| 49 |
|