Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,30 @@ 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:
|
|
@@ -46,6 +62,8 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
@@ -55,7 +73,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_weather_info(city: str) -> str:
|
| 13 |
+
"""A tool that fetches current weather information for a specified city.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
city: The name of the city to get weather information for (e.g., 'London', 'New York').
|
|
|
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
# Using a free weather API (OpenWeatherMap alternative)
|
| 19 |
+
# Note: In a real implementation, you'd want to use an API key
|
| 20 |
+
url = f"https://wttr.in/{city}?format=j1"
|
| 21 |
+
response = requests.get(url, timeout=10)
|
| 22 |
+
|
| 23 |
+
if response.status_code == 200:
|
| 24 |
+
data = response.json()
|
| 25 |
+
current = data['current_condition'][0]
|
| 26 |
+
weather_desc = current['weatherDesc'][0]['value']
|
| 27 |
+
temp_c = current['temp_C']
|
| 28 |
+
temp_f = current['temp_F']
|
| 29 |
+
humidity = current['humidity']
|
| 30 |
+
|
| 31 |
+
return f"Weather in {city}: {weather_desc}, {temp_c}°C ({temp_f}°F), Humidity: {humidity}%"
|
| 32 |
+
else:
|
| 33 |
+
return f"Could not fetch weather data for {city}"
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return f"Error fetching weather for '{city}': {str(e)}"
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 62 |
custom_role_conversions=None,
|
| 63 |
)
|
| 64 |
|
| 65 |
+
# Initialize additional tools
|
| 66 |
+
search_tool = DuckDuckGoSearchTool()
|
| 67 |
|
| 68 |
# Import tool from Hub
|
| 69 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[final_answer, get_weather_info, get_current_time_in_timezone, image_generation_tool, search_tool], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|