Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,35 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
import yaml
|
| 3 |
-
from smolagents import GradioUI, CodeAgent, HfApiModel
|
| 4 |
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
model = HfApiModel(
|
|
@@ -14,17 +39,16 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
| 14 |
custom_role_conversions=None,
|
| 15 |
)
|
| 16 |
|
| 17 |
-
web_search = DuckDuckGoSearchTool()
|
| 18 |
-
visit_webpage = VisitWebpageTool()
|
| 19 |
-
final_answer = FinalAnswerTool()
|
| 20 |
|
|
|
|
|
|
|
| 21 |
|
| 22 |
with open("prompts.yaml", 'r') as stream:
|
| 23 |
prompt_templates = yaml.safe_load(stream)
|
| 24 |
-
|
| 25 |
agent = CodeAgent(
|
| 26 |
model=model,
|
| 27 |
-
tools=[
|
| 28 |
max_steps=6,
|
| 29 |
verbosity_level=1,
|
| 30 |
grammar=None,
|
|
@@ -34,4 +58,5 @@ agent = CodeAgent(
|
|
| 34 |
prompt_templates=prompt_templates
|
| 35 |
)
|
| 36 |
|
|
|
|
| 37 |
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 |
|
| 7 |
+
from Gradio_UI import GradioUI
|
| 8 |
+
|
| 9 |
+
@tool
|
| 10 |
+
def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 11 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 12 |
+
"""A tool that does nothing yet
|
| 13 |
+
Args:
|
| 14 |
+
arg1: the first argument
|
| 15 |
+
arg2: the second argument
|
| 16 |
+
"""
|
| 17 |
+
return "What magic will you build ?"
|
| 18 |
+
|
| 19 |
+
@tool
|
| 20 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 21 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 22 |
+
Args:
|
| 23 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 24 |
+
"""
|
| 25 |
+
try:
|
| 26 |
+
# Create timezone object
|
| 27 |
+
tz = pytz.timezone(timezone)
|
| 28 |
+
# Get current time in that timezone
|
| 29 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 30 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 33 |
|
| 34 |
|
| 35 |
model = HfApiModel(
|
|
|
|
| 39 |
custom_role_conversions=None,
|
| 40 |
)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Import tool from Hub
|
| 44 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 45 |
|
| 46 |
with open("prompts.yaml", 'r') as stream:
|
| 47 |
prompt_templates = yaml.safe_load(stream)
|
| 48 |
+
|
| 49 |
agent = CodeAgent(
|
| 50 |
model=model,
|
| 51 |
+
tools=[image_generation_tool,get_current_time_in_timezone,DuckDuckGoSearchTool()], ## add or remove tools here
|
| 52 |
max_steps=6,
|
| 53 |
verbosity_level=1,
|
| 54 |
grammar=None,
|
|
|
|
| 58 |
prompt_templates=prompt_templates
|
| 59 |
)
|
| 60 |
|
| 61 |
+
|
| 62 |
GradioUI(agent).launch()
|