Spaces:
Running
Running
Updated app.py
Browse filesAdded new dataset search
app.py
CHANGED
@@ -1,24 +1,12 @@
|
|
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 |
-
#
|
11 |
-
@tool
|
12 |
-
# def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
13 |
-
# #Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
# """A tool that does nothing yet
|
15 |
-
# Args:
|
16 |
-
# arg1: the first argument
|
17 |
-
# arg2: the second argument
|
18 |
-
# """
|
19 |
-
# return "What magic will you build ?"
|
20 |
-
|
21 |
-
|
22 |
@tool
|
23 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
24 |
"""
|
@@ -50,45 +38,45 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
50 |
except Exception as e:
|
51 |
return f"Error fetching datasets for '{arg1}': {str(e)}"
|
52 |
|
53 |
-
|
54 |
@tool
|
55 |
def get_current_time_in_timezone(timezone: str) -> str:
|
56 |
-
"""
|
|
|
|
|
57 |
Args:
|
58 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
|
|
|
59 |
"""
|
60 |
try:
|
61 |
-
# Create timezone object
|
62 |
tz = pytz.timezone(timezone)
|
63 |
-
# Get current time in that timezone
|
64 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
65 |
return f"The current local time in {timezone} is: {local_time}"
|
66 |
except Exception as e:
|
67 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
68 |
|
69 |
-
|
70 |
final_answer = FinalAnswerTool()
|
71 |
|
72 |
-
#
|
73 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
74 |
-
|
75 |
model = HfApiModel(
|
76 |
-
max_tokens=2096,
|
77 |
-
temperature=0.5,
|
78 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
79 |
-
custom_role_conversions=None,
|
80 |
)
|
81 |
|
82 |
-
|
83 |
-
# Import tool from Hub
|
84 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
85 |
|
|
|
86 |
with open("prompts.yaml", 'r') as stream:
|
87 |
prompt_templates = yaml.safe_load(stream)
|
88 |
-
|
|
|
89 |
agent = CodeAgent(
|
90 |
model=model,
|
91 |
-
tools=[final_answer,my_custom_tool],
|
92 |
max_steps=6,
|
93 |
verbosity_level=1,
|
94 |
grammar=None,
|
@@ -98,5 +86,5 @@ agent = CodeAgent(
|
|
98 |
prompt_templates=prompt_templates
|
99 |
)
|
100 |
|
101 |
-
|
102 |
-
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 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
from Gradio_UI import GradioUI
|
8 |
|
9 |
+
# Custom Tool to fetch datasets related to body parts or imaging types
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
@tool
|
11 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
12 |
"""
|
|
|
38 |
except Exception as e:
|
39 |
return f"Error fetching datasets for '{arg1}': {str(e)}"
|
40 |
|
|
|
41 |
@tool
|
42 |
def get_current_time_in_timezone(timezone: str) -> str:
|
43 |
+
"""
|
44 |
+
A tool that fetches the current local time in a specified timezone.
|
45 |
+
|
46 |
Args:
|
47 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
48 |
+
|
49 |
+
Returns:
|
50 |
+
A string showing the current local time in the specified timezone.
|
51 |
"""
|
52 |
try:
|
|
|
53 |
tz = pytz.timezone(timezone)
|
|
|
54 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
55 |
return f"The current local time in {timezone} is: {local_time}"
|
56 |
except Exception as e:
|
57 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
58 |
|
|
|
59 |
final_answer = FinalAnswerTool()
|
60 |
|
61 |
+
# Model setup
|
|
|
|
|
62 |
model = HfApiModel(
|
63 |
+
max_tokens=2096,
|
64 |
+
temperature=0.5,
|
65 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # this model may be overloaded
|
66 |
+
custom_role_conversions=None,
|
67 |
)
|
68 |
|
69 |
+
# Load tool from hub
|
|
|
70 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
71 |
|
72 |
+
# Load prompt templates
|
73 |
with open("prompts.yaml", 'r') as stream:
|
74 |
prompt_templates = yaml.safe_load(stream)
|
75 |
+
|
76 |
+
# Create the agent
|
77 |
agent = CodeAgent(
|
78 |
model=model,
|
79 |
+
tools=[final_answer, get_current_time_in_timezone, my_custom_tool], # add your tools here
|
80 |
max_steps=6,
|
81 |
verbosity_level=1,
|
82 |
grammar=None,
|
|
|
86 |
prompt_templates=prompt_templates
|
87 |
)
|
88 |
|
89 |
+
# Launch the UI
|
90 |
+
GradioUI(agent).launch()
|