Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,36 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -52,16 +72,24 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 52 |
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
| 62 |
planning_interval=None,
|
| 63 |
-
name=
|
| 64 |
-
description=
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
| 67 |
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
+
def get_weather_info(city: str) -> str:
|
| 12 |
+
"""A tool that fetches current weather information for a given city
|
|
|
|
| 13 |
Args:
|
| 14 |
+
city: The name of the city to get weather for
|
|
|
|
| 15 |
"""
|
| 16 |
+
try:
|
| 17 |
+
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
| 18 |
+
params = {
|
| 19 |
+
'q': city,
|
| 20 |
+
'appid': OPENWEATHER_API_KEY,
|
| 21 |
+
'units': 'metric' # This will get temperature in Celsius
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
response = requests.get(base_url, params=params)
|
| 25 |
+
response.raise_for_status() # Raises an HTTPError for bad responses
|
| 26 |
+
|
| 27 |
+
weather_data = response.json()
|
| 28 |
+
|
| 29 |
+
# Extract relevant information
|
| 30 |
+
temperature = weather_data['main']['temp']
|
| 31 |
+
conditions = weather_data['weather'][0]['description']
|
| 32 |
+
humidity = weather_data['main']['humidity']
|
| 33 |
+
wind_speed = weather_data['wind']['speed']
|
| 34 |
+
|
| 35 |
+
return (f"Current weather in {city}:\n"
|
| 36 |
+
f"Temperature: {temperature}°C\n"
|
| 37 |
+
f"Conditions: {conditions}\n"
|
| 38 |
+
f"Humidity: {humidity}%\n"
|
| 39 |
+
f"Wind Speed: {wind_speed} m/s")
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 72 |
|
| 73 |
with open("prompts.yaml", 'r') as stream:
|
| 74 |
prompt_templates = yaml.safe_load(stream)
|
| 75 |
+
|
| 76 |
+
search_tool = DuckDuckGoSearchTool()
|
| 77 |
+
|
| 78 |
agent = CodeAgent(
|
| 79 |
model=model,
|
| 80 |
+
tools=[
|
| 81 |
+
final_answer,
|
| 82 |
+
search_tool,
|
| 83 |
+
image_generation_tool,
|
| 84 |
+
get_current_time_in_timezone,
|
| 85 |
+
get_weather_info
|
| 86 |
+
],
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|
| 90 |
planning_interval=None,
|
| 91 |
+
name="Multi-tool assistant",
|
| 92 |
+
description=description="An agent capable of searching, generating images, checking time zones, and getting weather information.",
|
| 93 |
prompt_templates=prompt_templates
|
| 94 |
)
|
| 95 |
|