Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
import os
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 9 |
-
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
-
#
|
| 13 |
@tool
|
| 14 |
-
def my_custom_tool(arg1:str, arg2:int)-> str:
|
| 15 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 16 |
"""A tool that does nothing yet
|
| 17 |
Args:
|
| 18 |
arg1: the first argument
|
|
@@ -27,37 +24,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 27 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 28 |
"""
|
| 29 |
try:
|
| 30 |
-
# Create timezone object
|
| 31 |
tz = pytz.timezone(timezone)
|
| 32 |
-
# Get current time in that timezone
|
| 33 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 34 |
return f"The current local time in {timezone} is: {local_time}"
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
-
|
| 39 |
final_answer = FinalAnswerTool()
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 43 |
-
|
| 44 |
model = HfApiModel(
|
| 45 |
-
max_tokens=2096,
|
| 46 |
-
temperature=0.5,
|
| 47 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 48 |
-
custom_role_conversions=None,
|
| 49 |
)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
# Import tool from Hub
|
| 53 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 54 |
-
|
| 55 |
with open("prompts.yaml", 'r') as stream:
|
| 56 |
prompt_templates = yaml.safe_load(stream)
|
| 57 |
-
|
|
|
|
| 58 |
agent = CodeAgent(
|
| 59 |
model=model,
|
| 60 |
-
tools=[final_answer
|
| 61 |
max_steps=6,
|
| 62 |
verbosity_level=1,
|
| 63 |
grammar=None,
|
|
@@ -67,5 +59,5 @@ agent = CodeAgent(
|
|
| 67 |
prompt_templates=prompt_templates
|
| 68 |
)
|
| 69 |
|
| 70 |
-
|
| 71 |
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 |
import os
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Define custom tools
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
|
|
| 13 |
"""A tool that does nothing yet
|
| 14 |
Args:
|
| 15 |
arg1: the first argument
|
|
|
|
| 24 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 25 |
"""
|
| 26 |
try:
|
|
|
|
| 27 |
tz = pytz.timezone(timezone)
|
|
|
|
| 28 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 29 |
return f"The current local time in {timezone} is: {local_time}"
|
| 30 |
except Exception as e:
|
| 31 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 32 |
|
| 33 |
+
# Initialize tools
|
| 34 |
final_answer = FinalAnswerTool()
|
| 35 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 36 |
|
| 37 |
+
# Initialize model
|
|
|
|
|
|
|
| 38 |
model = HfApiModel(
|
| 39 |
+
max_tokens=2096,
|
| 40 |
+
temperature=0.5,
|
| 41 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 42 |
+
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
| 45 |
+
# Load prompt templates
|
|
|
|
|
|
|
|
|
|
| 46 |
with open("prompts.yaml", 'r') as stream:
|
| 47 |
prompt_templates = yaml.safe_load(stream)
|
| 48 |
+
|
| 49 |
+
# Initialize agent with all tools
|
| 50 |
agent = CodeAgent(
|
| 51 |
model=model,
|
| 52 |
+
tools=[final_answer, image_generation_tool, my_custom_tool, get_current_time_in_timezone],
|
| 53 |
max_steps=6,
|
| 54 |
verbosity_level=1,
|
| 55 |
grammar=None,
|
|
|
|
| 59 |
prompt_templates=prompt_templates
|
| 60 |
)
|
| 61 |
|
| 62 |
+
# Launch the UI
|
| 63 |
GradioUI(agent).launch()
|