Spaces:
Runtime error
Runtime error
Update app.py
Browse files12342 unmodified lines7891011121314151617181920212210 unmodified lines3334353637381 unmodified line404142434445464748495051522 unmodified lines555657585960613 unmodified lines6566676869from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport requestsimport pytz2 unmodified linesfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_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:10 unmodified linesexcept Exception as e:return f"Error fetching time for timezone '{timezone}': {str(e)}"final_answer = FinalAnswerTool()1 unmodified line# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'model = HfApiModel(max_tokens=2096,temperature=0.5,model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloadedcustom_role_conversions=None,)# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)2 unmodified linesagent = CodeAgent(model=model,tools=[final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,3 unmodified linesprompt_templates=prompt_templates)GradioUI(agent).launch()12342 unmodified lines78910111213141516171819202110 unmodified lines3233343536373839404142434445464748495051521 unmodified line5455565758596061626364652 unmodified lines686970717273743 unmodified lines78798081from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, toolimport datetimeimport requestsimport pytz2 unmodified linesfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity!@tooldef my_custom_tool(arg1: str, arg2: int) -> str: # it's important to specify the return type"""A tool that does nothing yet.Args:arg1: the first argumentarg2: the second argument"""return "What magic will you build?"@tooldef get_current_time_in_timezone(timezone: str) -> str:10 unmodified linesexcept Exception as e:return f"Error fetching time for timezone '{timezone}': {str(e)}"@tooldef get_weather(city: str) -> str:"""A tool that fetches current weather information for a given city.Args:city: The name of the city for which to fetch the weather."""try:# Using wttr.in as a simple weather API endpoint for demonstration purposesresponse = requests.get(f"https://wttr.in/{city}?format=3")if response.status_code == 200:return f"Weather for {city}: {response.text.strip()}"else:return f"Could not fetch weather for {city}. Status code: {response.status_code}"except Exception as e:return f"Error fetching weather for {city}: {str(e)}"final_answer = FinalAnswerTool()1 unmodified line# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'model = HfApiModel(max_tokens=2096,temperature=0.5,model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloadedcustom_role_conversions=None,)# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)2 unmodified linesagent = CodeAgent(model=model,tools=[final_answer, my_custom_tool, get_current_time_in_timezone, get_weather],max_steps=6,verbosity_level=1,grammar=None,3 unmodified linesprompt_templates=prompt_templates)GradioUI(agent).launch()
app.py+26-14