Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,30 +9,42 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
|
| 16 |
Args:
|
| 17 |
-
|
| 18 |
-
max_results (int): The maximum number of search results to return.
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
-
str:
|
| 22 |
"""
|
| 23 |
-
|
| 24 |
-
results = ddgs.text(query, max_results=max_results)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
f"{i}. {r.get('title')}\n"
|
| 30 |
-
f"{r.get('href')}\n"
|
| 31 |
-
f"{r.get('body')}\n"
|
| 32 |
-
)
|
| 33 |
|
| 34 |
-
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -63,7 +75,7 @@ with open("prompts.yaml", "r") as stream:
|
|
| 63 |
|
| 64 |
agent = CodeAgent(
|
| 65 |
model=model,
|
| 66 |
-
tools=[
|
| 67 |
max_steps=6,
|
| 68 |
verbosity_level=1,
|
| 69 |
prompt_templates=prompt_templates
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
@tool
|
| 12 |
+
def get_current_weather(city: str) -> str:
|
| 13 |
"""
|
| 14 |
+
Get current weather for a city using Open-Meteo API.
|
| 15 |
|
| 16 |
Args:
|
| 17 |
+
city (str): The city name.
|
|
|
|
| 18 |
|
| 19 |
Returns:
|
| 20 |
+
str: Current temperature and wind speed.
|
| 21 |
"""
|
| 22 |
+
import requests
|
|
|
|
| 23 |
|
| 24 |
+
# Get coordinates
|
| 25 |
+
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}"
|
| 26 |
+
geo_response = requests.get(geo_url).json()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
if "results" not in geo_response:
|
| 29 |
+
return "City not found."
|
| 30 |
|
| 31 |
+
lat = geo_response["results"][0]["latitude"]
|
| 32 |
+
lon = geo_response["results"][0]["longitude"]
|
| 33 |
+
|
| 34 |
+
# Get weather
|
| 35 |
+
weather_url = (
|
| 36 |
+
f"https://api.open-meteo.com/v1/forecast?"
|
| 37 |
+
f"latitude={lat}&longitude={lon}¤t_weather=true"
|
| 38 |
+
)
|
| 39 |
+
weather_data = requests.get(weather_url).json()
|
| 40 |
+
|
| 41 |
+
current = weather_data.get("current_weather", {})
|
| 42 |
+
|
| 43 |
+
return (
|
| 44 |
+
f"Current weather in {city}: "
|
| 45 |
+
f"{current.get('temperature')}°C, "
|
| 46 |
+
f"Wind {current.get('windspeed')} km/h"
|
| 47 |
+
)
|
| 48 |
|
| 49 |
@tool
|
| 50 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 75 |
|
| 76 |
agent = CodeAgent(
|
| 77 |
model=model,
|
| 78 |
+
tools=[get_current_weather, get_current_time_in_timezone, final_answer],
|
| 79 |
max_steps=6,
|
| 80 |
verbosity_level=1,
|
| 81 |
prompt_templates=prompt_templates
|