CoolFace
Apppublic

nit-sparky/First_agent_template

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py72 linesDownload Raw Back to root
1from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, FinalAnswerTool2import datetime3import requests4import pytz5import yaml6 7 8from Gradio_UI import GradioUI9 10@tool11def quirky_reverse(arg1: str, arg2: int) -> str:12    """Reverses the input string and randomly capitalizes some letters.13    14    Args:15        arg1: The text to reverse and stylize.16        arg2: A seed number to control randomness (so results can be repeated).17    """18    import random19 20    random.seed(arg2)21    reversed_text = arg1[::-1]22    styled = ''.join(23        c.upper() if random.random() > 0.5 else c.lower() for c in reversed_text24    )25    return styled26 27@tool28def get_current_time_in_timezone(timezone: str) -> str:29    """A tool that fetches the current local time in a specified timezone.30    Args:31        timezone: A string representing a valid timezone (e.g., 'America/New_York').32    """33    try:34        # Create timezone object35        tz = pytz.timezone(timezone)36        # Get current time in that timezone37        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")38        return f"The current local time in {timezone} is: {local_time}"39    except Exception as e:40        return f"Error fetching time for timezone '{timezone}': {str(e)}"41 42 43final_answer = FinalAnswerTool()44 45model = HfApiModel(46max_tokens=2096,47temperature=0.5,48model_id='Qwen/Qwen2.5-Coder-32B-Instruct',49custom_role_conversions=None,50)51 52 53# Import tool from Hub54image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)55 56 57with open("prompts.yaml", 'r') as stream:58    prompt_templates = yaml.safe_load(stream)59    60agent = CodeAgent(61    model=model,62    tools=[quirky_reverse, get_current_time_in_timezone, image_generation_tool, final_answer],63    max_steps=7,64    verbosity_level=1,65    grammar=None,66    planning_interval=None,67    name=None,68    description=None,69    prompt_templates=prompt_templates70)71 72GradioUI(agent).launch()