SimplyKindAI/First_agent_template_new
0
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7 8from Gradio_UI import GradioUI9 10 11# Import tool from Hub12image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)13 14 15# Below is an example of a tool that does nothing. Amaze us with your creativity !16@tool17def generate_image_from_mood(mood: str)-> dict: #it's import to specify the return type18 """A tool that detects person's mood and generate immersive image 19 Args:20 mood: the user's mood (e.g. 'Sad', 'Happy')21 """22 23 return image_generation_tool({mood})24 25@tool26def get_current_time_in_timezone(timezone: str) -> str:27 """A tool that fetches the current local time in a specified timezone.28 Args:29 timezone: A string representing a valid timezone (e.g., 'America/New_York').30 """31 try:32 # Create timezone object33 tz = pytz.timezone(timezone)34 # Get current time in that timezone35 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")36 return f"The current local time in {timezone} is: {local_time}"37 except Exception as e:38 return f"Error fetching time for timezone '{timezone}': {str(e)}"39 40 41final_answer = FinalAnswerTool()42 43# 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:44# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 45 46model = HfApiModel(47max_tokens=2096,48temperature=0.5,49model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded50custom_role_conversions=None,51)52 53 54 55 56with open("prompts.yaml", 'r') as stream:57 prompt_templates = yaml.safe_load(stream)58 59agent = CodeAgent(60 model=model,61 tools=[final_answer,generate_image_from_mood, image_generation_tool, get_current_time_in_timezone ], ## add your tools here (don't remove final answer)62 max_steps=6,63 verbosity_level=1,64 grammar=None,65 planning_interval=None,66 name=None,67 description=None,68 prompt_templates=prompt_templates69)70 71 72GradioUI(agent).launch()