Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
@@ -6,33 +7,8 @@ import yaml
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from Gradio_UI import GradioUI
|
8 |
|
9 |
-
#
|
10 |
-
@
|
11 |
-
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
12 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
13 |
-
"""A tool that does nothing yet
|
14 |
-
Args:
|
15 |
-
arg1: the first argument
|
16 |
-
arg2: the second argument
|
17 |
-
"""
|
18 |
-
return "What magic will you build ?"
|
19 |
-
|
20 |
-
@tool
|
21 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
22 |
-
"""A tool that fetches the current local time in a specified timezone.
|
23 |
-
Args:
|
24 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
25 |
-
"""
|
26 |
-
try:
|
27 |
-
# Create timezone object
|
28 |
-
tz = pytz.timezone(timezone)
|
29 |
-
# Get current time in that timezone
|
30 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
31 |
-
return f"The current local time in {timezone} is: {local_time}"
|
32 |
-
except Exception as e:
|
33 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
34 |
-
@tool
|
35 |
-
def generate_keywords(topic: str, num_keywords: int) -> str:
|
36 |
"""A tool that generates relevant keywords for a given topic
|
37 |
|
38 |
Args:
|
@@ -96,16 +72,16 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
96 |
with open("prompts.yaml", 'r') as stream:
|
97 |
prompt_templates = yaml.safe_load(stream)
|
98 |
|
99 |
-
# Create agent
|
100 |
agent = CodeAgent(
|
101 |
-
|
102 |
-
[
|
103 |
image_generation_tool,
|
104 |
get_current_time_in_timezone,
|
105 |
generate_keywords,
|
106 |
final_answer,
|
107 |
DuckDuckGoSearchTool()
|
108 |
],
|
|
|
109 |
max_steps=6,
|
110 |
verbosity_level=1,
|
111 |
grammar=None,
|
@@ -115,4 +91,5 @@ agent = CodeAgent(
|
|
115 |
prompt_templates=prompt_templates
|
116 |
)
|
117 |
|
|
|
118 |
GradioUI(agent).launch()
|
|
|
1 |
+
# Imports
|
2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
3 |
import datetime
|
4 |
import requests
|
|
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# Tool definitions
|
11 |
+
@tooldef generate_keywords(topic: str, num_keywords: int) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
"""A tool that generates relevant keywords for a given topic
|
13 |
|
14 |
Args:
|
|
|
72 |
with open("prompts.yaml", 'r') as stream:
|
73 |
prompt_templates = yaml.safe_load(stream)
|
74 |
|
75 |
+
# Create agent with tools first, then model as named parameter
|
76 |
agent = CodeAgent(
|
77 |
+
tools=[
|
|
|
78 |
image_generation_tool,
|
79 |
get_current_time_in_timezone,
|
80 |
generate_keywords,
|
81 |
final_answer,
|
82 |
DuckDuckGoSearchTool()
|
83 |
],
|
84 |
+
model=model,
|
85 |
max_steps=6,
|
86 |
verbosity_level=1,
|
87 |
grammar=None,
|
|
|
91 |
prompt_templates=prompt_templates
|
92 |
)
|
93 |
|
94 |
+
# Launch UI
|
95 |
GradioUI(agent).launch()
|