Spaces:
Sleeping
Sleeping
Added custom tools
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:
|
@@ -33,7 +49,10 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
36 |
|
|
|
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:
|
@@ -55,7 +74,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[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_current_weather(city: str) -> str:
|
13 |
+
"""Fetches the current weather for a given city.
|
|
|
14 |
Args:
|
15 |
+
city: Name of the city.
|
|
|
16 |
"""
|
17 |
+
try:
|
18 |
+
api_url = f"https://wttr.in/{city}?format=%C+%t"
|
19 |
+
response = requests.get(api_url)
|
20 |
+
return f"Current weather in {city}: {response.text}"
|
21 |
+
except Exception as e:
|
22 |
+
return f"Error fetching weather: {str(e)}"
|
23 |
+
|
24 |
+
@tool
|
25 |
+
def summarize_text(text: str) -> str:
|
26 |
+
"""Summarizes a given text.
|
27 |
+
Args:
|
28 |
+
text: The text to summarize.
|
29 |
+
"""
|
30 |
+
summary_model = HfApiModel(
|
31 |
+
max_tokens=512,
|
32 |
+
temperature=0.3,
|
33 |
+
model_id='facebook/bart-large-cnn'
|
34 |
+
)
|
35 |
+
return summary_model.generate(text)
|
36 |
|
37 |
@tool
|
38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
49 |
except Exception as e:
|
50 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
51 |
|
52 |
+
# Load external tools
|
53 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
54 |
|
55 |
+
duckduckgo_search = DuckDuckGoSearchTool()
|
56 |
final_answer = FinalAnswerTool()
|
57 |
|
58 |
# 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:
|
|
|
74 |
|
75 |
agent = CodeAgent(
|
76 |
model=model,
|
77 |
+
tools=[final_answer, duckduckgo_search, image_generation_tool, get_current_weather, summarize_text],
|
78 |
max_steps=6,
|
79 |
verbosity_level=1,
|
80 |
grammar=None,
|