Update app.py
Browse files1123453656778910111213141516171819202122232425262728293031323334353 unmodified lines3940411718194243444546472448495027515253543 unmodified lines5859606162
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport requestsimport pytzimport yamlfrom smolagents import GradioUI, CodeAgent, HfApiModel
from tools.web_search import DuckDuckGoSearchToolfrom tools.visit_webpage import VisitWebpageToolfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI
@tooldef my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type #Keep this format for the description / args / args description but feel free to modify the tool """A tool that does nothing yet Args: arg1: the first argument arg2: the second argument """ return "What magic will you build ?"
@tooldef get_current_time_in_timezone(timezone: str) -> str: """A tool that fetches the current local time in a specified timezone. Args: timezone: A string representing a valid timezone (e.g., 'America/New_York'). """ try: # Create timezone object tz = pytz.timezone(timezone) # Get current time in that timezone local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S") return f"The current local time in {timezone} is: {local_time}" except Exception as e: return f"Error fetching time for timezone '{timezone}': {str(e)}"
model = HfApiModel(3 unmodified linescustom_role_conversions=None,)
web_search = DuckDuckGoSearchTool()visit_webpage = VisitWebpageTool()final_answer = FinalAnswerTool()
# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream)
agent = CodeAgent( model=model, tools=[web_search, visit_webpage, final_answer], tools=[image_generation_tool,get_current_time_in_timezone,DuckDuckGoSearchTool()], ## add or remove tools here max_steps=6, verbosity_level=1, grammar=None,3 unmodified lines prompt_templates=prompt_templates)
GradioUI(agent).launch()app.py+35-10