Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,55 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -55,7 +94,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
import requests
|
11 |
+
|
12 |
+
@tool
|
13 |
+
def get_location() -> str:
|
14 |
+
"""Retrieves the user's current location based on their IP address.
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
A string containing the latitude and longitude of the user's location.
|
18 |
+
"""
|
19 |
+
try:
|
20 |
+
response = requests.get("https://ipinfo.io/json")
|
21 |
+
data = response.json()
|
22 |
+
location = data.get("loc", "Unknown location")
|
23 |
+
return f"Your approximate location is: {location} (Latitude, Longitude)"
|
24 |
+
except Exception as e:
|
25 |
+
return f"Error retrieving location: {str(e)}"
|
26 |
+
|
27 |
@tool
|
28 |
+
def get_weather(location: str) -> str:
|
29 |
+
"""Gets the current weather for a given location.
|
30 |
+
|
31 |
Args:
|
32 |
+
location: The latitude and longitude or city name.
|
33 |
+
|
34 |
+
Returns:
|
35 |
+
A string containing the current weather conditions for the specified location.
|
36 |
"""
|
37 |
+
try:
|
38 |
+
api_key = "your_openweathermap_api_key" # Replace with your OpenWeatherMap API key
|
39 |
+
base_url = "https://api.openweathermap.org/data/2.5/weather"
|
40 |
+
|
41 |
+
params = {
|
42 |
+
"q": location, # You can also use lat, lon instead of city name
|
43 |
+
"appid": api_key,
|
44 |
+
"units": "metric" # Use "imperial" for Fahrenheit
|
45 |
+
}
|
46 |
+
|
47 |
+
response = requests.get(base_url, params=params)
|
48 |
+
weather_data = response.json()
|
49 |
+
|
50 |
+
if weather_data.get("cod") != 200:
|
51 |
+
return f"Weather data not found for {location}."
|
52 |
+
|
53 |
+
temp = weather_data["main"]["temp"]
|
54 |
+
description = weather_data["weather"][0]["description"]
|
55 |
+
return f"The current weather in {location} is {temp}°C with {description}."
|
56 |
+
|
57 |
+
except Exception as e:
|
58 |
+
return f"Error retrieving weather data: {str(e)}"
|
59 |
|
60 |
@tool
|
61 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
94 |
|
95 |
agent = CodeAgent(
|
96 |
model=model,
|
97 |
+
tools=[final_answer, get_location, get_weather, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
98 |
max_steps=6,
|
99 |
verbosity_level=1,
|
100 |
grammar=None,
|