Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 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
|
|
@@ -37,8 +40,8 @@ def get_weather_info(city: str) -> str:
|
|
| 37 |
f"Conditions: {conditions}\n"
|
| 38 |
f"Humidity: {humidity}%\n"
|
| 39 |
f"Wind Speed: {wind_speed} m/s")
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,20 +58,18 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 55 |
except Exception as e:
|
| 56 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 57 |
|
| 58 |
-
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
|
| 61 |
-
# If the agent does not answer, the model is overloaded, please use another model or the following
|
|
|
|
| 62 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 63 |
-
|
| 64 |
model = HfApiModel(
|
| 65 |
-
max_tokens=2096,
|
| 66 |
-
temperature=0.5,
|
| 67 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 68 |
-
custom_role_conversions=None,
|
| 69 |
)
|
| 70 |
|
| 71 |
-
|
| 72 |
# Import tool from Hub
|
| 73 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 74 |
|
|
@@ -79,7 +80,7 @@ search_tool = DuckDuckGoSearchTool()
|
|
| 79 |
|
| 80 |
agent = CodeAgent(
|
| 81 |
model=model,
|
| 82 |
-
|
| 83 |
final_answer,
|
| 84 |
search_tool,
|
| 85 |
image_generation_tool,
|
|
@@ -90,10 +91,9 @@ agent = CodeAgent(
|
|
| 90 |
verbosity_level=1,
|
| 91 |
grammar=None,
|
| 92 |
planning_interval=None,
|
| 93 |
-
name="Multi-tool
|
| 94 |
-
description=
|
| 95 |
prompt_templates=prompt_templates
|
| 96 |
)
|
| 97 |
|
| 98 |
-
|
| 99 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import os
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Set up OpenWeather API key
|
| 11 |
+
OPENWEATHER_API_KEY = os.getenv('OPENWEATHER_API_KEY', 'your_api_key_here')
|
| 12 |
+
|
| 13 |
@tool
|
| 14 |
def get_weather_info(city: str) -> str:
|
| 15 |
"""A tool that fetches current weather information for a given city
|
|
|
|
| 40 |
f"Conditions: {conditions}\n"
|
| 41 |
f"Humidity: {humidity}%\n"
|
| 42 |
f"Wind Speed: {wind_speed} m/s")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Error fetching weather for city '{city}': {str(e)}"
|
| 45 |
|
| 46 |
@tool
|
| 47 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 60 |
|
|
|
|
| 61 |
final_answer = FinalAnswerTool()
|
| 62 |
|
| 63 |
+
# If the agent does not answer, the model is overloaded, please use another model or the following
|
| 64 |
+
# Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 65 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 66 |
model = HfApiModel(
|
| 67 |
+
max_tokens=2096,
|
| 68 |
+
temperature=0.5,
|
| 69 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
| 70 |
+
custom_role_conversions=None,
|
| 71 |
)
|
| 72 |
|
|
|
|
| 73 |
# Import tool from Hub
|
| 74 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 75 |
|
|
|
|
| 80 |
|
| 81 |
agent = CodeAgent(
|
| 82 |
model=model,
|
| 83 |
+
tools=[
|
| 84 |
final_answer,
|
| 85 |
search_tool,
|
| 86 |
image_generation_tool,
|
|
|
|
| 91 |
verbosity_level=1,
|
| 92 |
grammar=None,
|
| 93 |
planning_interval=None,
|
| 94 |
+
name="Multi-tool Assistant",
|
| 95 |
+
description="An agent capable of searching, generating images, checking time zones, and getting weather information.",
|
| 96 |
prompt_templates=prompt_templates
|
| 97 |
)
|
| 98 |
|
|
|
|
| 99 |
GradioUI(agent).launch()
|