Spaces:
Runtime error
Runtime error
| #Just havinfg the original template here, in case we need to duplicate | |
| from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool | |
| from datetime import datetime | |
| import requests | |
| import pytz | |
| import yaml | |
| from tools.final_answer import FinalAnswerTool | |
| from Gradio_UI import GradioUI | |
| # Belo is an example of a tool that does nothing. Amaze us with your creativity ! | |
| def time_left_for_event(event:str, date:str)-> str: #it's import to specify the return type | |
| """A tool that calculates the time left for a certain event | |
| Args: | |
| event: the event name (e.g., wedding, birthday, trip) | |
| date: the date of the event in YYYY-MM-DD format | |
| Returns: | |
| A string telling how many days, weeks, and months are left | |
| """ | |
| try: | |
| # Parse the input date | |
| event_date = datetime.strptime(date, '%Y-%m-%d') | |
| today = datetime.now() | |
| # Calculate the difference | |
| time_difference = event_date - today | |
| # Calculate days, weeks, and months | |
| days_left = time_difference.days | |
| weeks_left = days_left // 7 | |
| months_left = days_left // 30 # Approximate | |
| return f"For your {event}, you have approximately {months_left} months ({weeks_left} weeks or {days_left} days) left" | |
| except ValueError: | |
| return "Error: Please provide the date in YYYY-MM-DD format (e.g., 2024-12-25)" | |
| except Exception as e: | |
| return f"Error calculating time difference: {str(e)}" | |
| final_answer = FinalAnswerTool() | |
| 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, | |
| ) | |
| #deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | |
| #'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud' | |
| # Import tool from Hub | |
| image_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=[final_answer, time_left_for_event], ## add your tools here (don't remove final answer) | |
| max_steps=6, | |
| verbosity_level=1, | |
| grammar=None, | |
| planning_interval=None, | |
| name=None, | |
| description=None, | |
| prompt_templates=prompt_templates | |
| ) | |
| GradioUI(agent).launch() |