CoolFace
Apppublic

Sanath-18/First_agent

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py68 linesDownload Raw Back to root
1from smolagents import CodeAgent,load_tool,tool2from smolagents.models import OpenAIServerModel3import os4import datetime5import requests6import pytz7import yaml8from tools.final_answer import FinalAnswerTool9from customtools import get_top_pokemon, get_pokemon_details10from huggingface_hub import InferenceClient11 12from Gradio_UI import GradioUI13 14 15@tool16def get_current_time_in_timezone(timezone: str) -> str:17    """A tool that fetches the current local time in a specified timezone.18    Args:19        timezone: A string representing a valid timezone (e.g., 'America/New_York').20    """21    try:22        # Create timezone object23        tz = pytz.timezone(timezone)24        # Get current time in that timezone25        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")26        return f"The current local time in {timezone} is: {local_time}"27    except Exception as e:28        return f"Error fetching time for timezone '{timezone}': {str(e)}"29 30 31final_answer = FinalAnswerTool()32 33# 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:34# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 35 36GEMINI_API_KEY = 'your api key'37 38model = OpenAIServerModel(39    model_id="gemini-2.5-pro",  # Or "gemini-pro" or other compatible models40    api_base="https://generativelanguage.googleapis.com/v1beta/openai/", # Using OpenAI-compatible API base URL41    api_key=os.getenv("GEMINI_API_KEY"),42    max_tokens=2096,43    temperature=0.5,44    custom_role_conversions=None,45)46 47 48# Import tool from Hub49image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)50 51with open("prompts.yaml", 'r') as stream:52    prompt_templates = yaml.safe_load(stream)53    54agent = CodeAgent(55    model=model,56    tools=[final_answer,image_generation_tool,get_current_time_in_timezone,get_top_pokemon,get_pokemon_details], ## add your tools here (don't remove final answer)57    max_steps=6,58    verbosity_level=1,59    grammar=None,60    planning_interval=None,61    name=None,62    description=None,63    prompt_templates=prompt_templates64)65 66 67GradioUI(agent).launch()68