CoolFace
Apppublic

marcoluquer/multi_tool_agent

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py81 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_total_savings(years: int, interest_rate: float, amount: float) -> float:12    """13    Calculate the total accumulated savings from making fixed monthly deposits over a given number of years,14    with the deposits growing at a fixed annual interest rate.15 16    Args:17        years: The time horizon for the investment in years.18        interest_rate: The fixed annual interest rate (expressed as a decimal) applied to the savings.19        amount: The amount of money saved (or invested) each month.20 21    Returns:22        float: The total amount accumulated after the specified number of years.23    """24 25    total_savings = amount * ((1 + interest_rate/12)**(12*years) -1)  / (interest_rate/12)26    27    return total_savings28 29@tool30def get_current_time_in_timezone(timezone: str) -> str:31    """A tool that fetches the current local time in a specified timezone.32    Args:33        timezone: A string representing a valid timezone (e.g., 'America/New_York').34    """35    try:36        # Create timezone object37        tz = pytz.timezone(timezone)38        # Get current time in that timezone39        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")40        return f"The current local time in {timezone} is: {local_time}"41    except Exception as e:42        return f"Error fetching time for timezone '{timezone}': {str(e)}"43 44 45final_answer = FinalAnswerTool()46 47# 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:48# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 49 50model = HfApiModel(51max_tokens=2096,52temperature=0.5,53model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded54custom_role_conversions=None,55)56 57 58# Import tool from Hub59image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)60 61with open("prompts.yaml", 'r') as stream:62    prompt_templates = yaml.safe_load(stream)63    64agent = CodeAgent(65    model=model,66    tools=[final_answer,67           image_generation_tool,68           get_current_time_in_timezone,69           get_total_savings70          ], ## add your tools here (don't remove final answer)71    max_steps=6,72    verbosity_level=1,73    grammar=None,74    planning_interval=None,75    name=None,76    description=None,77    prompt_templates=prompt_templates78)79 80 81GradioUI(agent).launch()