Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,17 +7,30 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
#
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -37,7 +50,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
40 |
-
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
42 |
model = HfApiModel(
|
43 |
max_tokens=2096,
|
@@ -46,7 +59,6 @@ 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)
|
52 |
|
@@ -55,7 +67,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 |
+
# 1. Get Current Weather Data
|
11 |
@tool
|
12 |
+
def get_weather(city: str) -> str:
|
13 |
+
"""Fetches current weather information for a specified city.
|
|
|
14 |
Args:
|
15 |
+
city: The name of the city (e.g., 'New York').
|
16 |
+
Returns:
|
17 |
+
A string with the weather description and temperature.
|
18 |
"""
|
19 |
+
api_key = "ac662b5c2463cfa522e1acd2d4cf5a81"
|
20 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
21 |
+
|
22 |
+
try:
|
23 |
+
response = requests.get(url).json()
|
24 |
+
if response["cod"] != 200:
|
25 |
+
return f"Error: {response['message']}"
|
26 |
+
|
27 |
+
temp = response["main"]["temp"]
|
28 |
+
weather_desc = response["weather"][0]["description"]
|
29 |
+
return f"The current weather in {city} is {weather_desc} with a temperature of {temp}°C."
|
30 |
+
except Exception as e:
|
31 |
+
return f"Error fetching weather data: {str(e)}"
|
32 |
|
33 |
+
# 2. Get Current Time in Timezone
|
34 |
@tool
|
35 |
def get_current_time_in_timezone(timezone: str) -> str:
|
36 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
50 |
final_answer = FinalAnswerTool()
|
51 |
|
52 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
53 |
+
#model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
54 |
|
55 |
model = HfApiModel(
|
56 |
max_tokens=2096,
|
|
|
59 |
custom_role_conversions=None,
|
60 |
)
|
61 |
|
|
|
62 |
# Import tool from Hub
|
63 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
64 |
|
|
|
67 |
|
68 |
agent = CodeAgent(
|
69 |
model=model,
|
70 |
+
tools=[final_answer,image_generation_tool,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
71 |
max_steps=6,
|
72 |
verbosity_level=1,
|
73 |
grammar=None,
|