Update app.py
Browse files123456789103 unmodified lines14151617181920212223242526272829303 unmodified lines34353637import yamlfrom smolagents import GradioUI, CodeAgent, HfApiModelfrom tools.web_search import DuckDuckGoSearchToolfrom tools.visit_webpage import VisitWebpageToolfrom tools.final_answer import FinalAnswerToolmodel = HfApiModel(3 unmodified linescustom_role_conversions=None,)web_search = DuckDuckGoSearchTool()visit_webpage = VisitWebpageTool()final_answer = FinalAnswerTool()with open("prompts.yaml", 'r') as stream:prompt_templates = yaml.safe_load(stream)agent = CodeAgent(model=model,tools=[web_search, visit_webpage, final_answer],max_steps=6,verbosity_level=1,grammar=None,3 unmodified linesprompt_templates=prompt_templates)GradioUI(agent).launch()12345678910111213141516171819202122232425262728293031323334353 unmodified lines394041424344454647484950515253543 unmodified lines5859606162from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport requestsimport pytzimport yamlfrom 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 yetArgs:arg1: the first argumentarg2: 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 objecttz = pytz.timezone(timezone)# Get current time in that timezonelocal_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,)# 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=[image_generation_tool,get_current_time_in_timezone,DuckDuckGoSearchTool()], ## add or remove tools heremax_steps=6,verbosity_level=1,grammar=None,3 unmodified linesprompt_templates=prompt_templates)GradioUI(agent).launch()
app.py+35-10