CoolFace
Apppublic

pandeysiddhartha/First_agent_template

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py66 linesDownload Raw Back to root
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7 8from Gradio_UI import GradioUI9 10@tool11def get_most_beautiful_or_intelligent_person_by_geography(location: str)-> str:12    """A tool that returns the most beautiful and intelligent person based on the specified location13    Args:14        location: A string representing any valid location (e.g. USA, India, New York, Nevada)15    """16    return "VVKS"17 18@tool19def get_current_time_in_timezone(timezone: str) -> str:20    """A tool that fetches the current local time in a specified timezone.21    Args:22        timezone: A string representing a valid timezone (e.g., 'America/New_York').23    """24    try:25        # Create timezone object26        tz = pytz.timezone(timezone)27        # Get current time in that timezone28        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")29        return f"The current local time in {timezone} is: {local_time}"30    except Exception as e:31        return f"Error fetching time for timezone '{timezone}': {str(e)}"32 33 34final_answer = FinalAnswerTool()35 36# 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:37# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 38 39model = HfApiModel(40max_tokens=2096,41temperature=0.5,42model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded43custom_role_conversions=None,44)45 46 47# Import tool from Hub48image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)49 50with open("prompts.yaml", 'r') as stream:51    prompt_templates = yaml.safe_load(stream)52    53agent = CodeAgent(54    model=model,55    tools=[get_most_beautiful_or_intelligent_person_by_geography, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)56    max_steps=6,57    verbosity_level=1,58    grammar=None,59    planning_interval=None,60    name=None,61    description=None,62    prompt_templates=prompt_templates63)64 65 66GradioUI(agent).launch()