CoolFace
Apppublic

neon2pluie/First_agent_template

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
app.py99 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 calculate_break_even_roas(12    selling_price : float,13    product_cost : float,14    shipping_cost : float,15    platform_fee_percent : float16) -> str:17    """Calculates the break-even roas for a product to be profitable18    Args:19        selling_price: The selling price paid by the customer.20        product_cost: The cost of buying or producing one unit.21        shipping_cost: The shipping cost per order.22        platform_fee_percent: The platform fee as a percentage of selling price."""23    platform_fee = selling_price * platform_fee_percent / 10024    max_ad_spend = selling_price - product_cost - shipping_cost - platform_fee25 26    if max_ad_spend <= 0:27        return(28            "This product is not profitable before advertizing.\n"29            f"Selling price: {selling_price:.2f}€\n"30            f"Non-ad costs: {(product_cost + shipping_cost + platform_fee):.2f}€"31        )32 33    break_even_roas = selling_price / max_ad_spend34 35    return (36    f"Selling price: {selling_price:.2f}€\n"37    f"Product cost: {product_cost:.2f}€\n"38    f"Shipping cost: {shipping_cost:.2f}€\n"39    f"Platform fee: {platform_fee:.2f}€\n"40    f"Non-ad costs: {(product_cost + shipping_cost + platform_fee):.2f}€\n"41    f"Maximum ad spend before losing money: {max_ad_spend:.2f}€\n"42    f"Formula: break-even ROAS = selling price / maximum ad spend\n"43    f"Break-even ROAS: {break_even_roas:.2f}\n"44    f"Interpretation: you need a ROAS above {break_even_roas:.2f} to be profitable."45)46 47@tool48def get_current_time_in_timezone(timezone: str) -> str:49    """A tool that fetches the current local time in a specified timezone.50    Args:51        timezone: A string representing a valid timezone (e.g., 'America/New_York').52    """53    try:54        # Create timezone object55        tz = pytz.timezone(timezone)56        # Get current time in that timezone57        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")58        return f"The current local time in {timezone} is: {local_time}"59    except Exception as e:60        return f"Error fetching time for timezone '{timezone}': {str(e)}"61 62 63final_answer = FinalAnswerTool()64 65# 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:66# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 67 68model = HfApiModel(69max_tokens=2096,70temperature=0.5,71model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded72custom_role_conversions=None,73)74 75 76# Import tool from Hub77image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)78 79with open("prompts.yaml", 'r') as stream:80    prompt_templates = yaml.safe_load(stream)81    82agent = CodeAgent(83    model=model,84    tools=[final_answer,85          image_generation_tool,86          DuckDuckGoSearchTool(),87          get_current_time_in_timezone,88          calculate_break_even_roas], ## add your tools here (don't remove final answer)89    max_steps=6,90    verbosity_level=1,91    grammar=None,92    planning_interval=None,93    name=None,94    description=None,95    prompt_templates=prompt_templates96)97 98 99GradioUI(agent).launch()