from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool import datetime import requests import pytz import yaml from tools.final_answer import FinalAnswerTool from Gradio_UI import GradioUI # Below is an example of a tool that does nothing. Amaze us with your creativity ! @tool def calculator(number1: float, number2: float, operation: str)-> float: """A tool that does three kinds of maths operations: sum, subtract, divide, or multiply. Args: number1: The first float number, it can be int number2: the second float number, it can be int operation: the type of math operation to carry out, it can be sum, subtraction (subtract), division(divide), or multiplication (multiply). """ try: if type(number1)== int: number1= float(number1) if type(number2)== int: number2= float(number2) if operation == "sum": result= number1 + number2 elif operation == "subtract": result= number1 - number2 elif operation == "divide": result= number1 /number2 elif operation == "multiply": result= number1 * number2 return result except Exception as e: return f"Error: {e}. Operation not surpported or missing arguments." @tool def sing_defying_gravity()-> str: #it's import to specify the return type """A tool that returns the lyrics for Defying Gravity Args: no arguments """ lyrics= """ [Glinda] Elphaba Why couldn't you have stayed calm for once Instead of flying off the handle? I hope you're happy I hope you're happy now I hope you're happy how you've hurt your cause forever I hope you think you're clever [Elphaba] I hope you're happy I hope you're happy too I hope you're proud how you would grovel in submission To feed your own ambition [Galinda and Elphaba] So though I can't imagine how I hope you're happy right now [Glinda] Elphie, listen to me Just say you're sorry You can still be with the wizard What you've worked and waited for You can have all you ever wanted [Elphaba] I know But I don't want it No I can't want it anymore Something has changed within me Something is not the same I'm through with playing by the rules of someone else's game Too late for second-guessing Too late to go back to sleep It's time to trust my instincts Close my eyes and leap It's time to try defying gravity I think I'll try defying gravity And you can't pull me down [Glinda] Can't I make you understand You're having delusions of grandeur? [Elphaba] I'm through accepting limits 'Cause someone says they're so Some things I cannot change But till I try, I'll never know Too long I've been afraid of Losing love, I guess I've lost Well, if that's love It comes at much too high a cost I'd sooner buy defying gravity Kiss me goodbye, I'm defying gravity And you can't pull me down Glinda Come with me Think of what we could do Together Unlimited Together we're unlimited Together we'll be the greatest team there's ever been, Glinda Dreams the way we planned 'em [Glinda] If we work in tandem [Glinda and Elphaba] There's no fight we cannot win Just you and I defying gravity With you and I defying gravity [Elphaba] They'll never bring us down Well, are you coming? [Glinda] I hope you're happy Now that you're choosing this [Elphaba] You too I hope it brings you bliss [Glinda and Elphaba] I really hope you get it And you don't live to regret it I hope you're happy in the end I hope you're happy, my friend [Elphaba] No, leave her alone She hasn't done anything wrong I'm the one you want I'm the one you want It's me It's me So if you care to find me, look to the western sky As someone told me lately Everyone deserves the chance to fly And if I'm flying solo At least I'm flying free To those who'd ground me Take a message back from me Tell them how I am defying gravity I'm flying high, defying gravity And soon I'll match them in renown Unlimited Unlimited Unlimited, oh And nobody in all of Oz No wizard that there is or was Is ever gonna bring me down [Glinda] I hope you're happy [Citizens of Oz and Elphaba] Look at her, she's wicked, kill her! (Bring me down) no one mourns the wicked So we've got to bring her (Oh) down Down, woah """ return lyrics @tool def 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)}" final_answer = FinalAnswerTool() # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder: # 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 overloaded custom_role_conversions=None, ) # Import tool from Hub image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True) search_tool = DuckDuckGoSearchTool() with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream) agent = CodeAgent( model=model, tools=[final_answer, image_generation_tool, search_tool, calculator,sing_defying_gravity], ## add your tools here (don't remove final answer) max_steps=6, verbosity_level=1, grammar=None, planning_interval=None, name="Dumbo", description=None, prompt_templates=prompt_templates ) GradioUI(agent).launch()