from smolagents import CodeAgent, HfApiModel, load_tool, tool import datetime import requests import pytz import yaml from tools.final_answer import FinalAnswerTool from Gradio_UI import GradioUI # Custom tool for web search to find authentic Ethiopian food images @tool def search_ethiopian_food_authentic(food_name: str) -> str: """Search for authentic Ethiopian food images to understand exact appearance Args: food_name: Name of the Ethiopian food (e.g., "injera", "doro wat", "tibs") """ try: # Use web search to find authentic images and descriptions search_query = f"authentic Ethiopian {food_name} traditional appearance ingredients presentation" # This would connect to your web_search_exa tool return f"Searching for authentic Ethiopian {food_name}..." except Exception as e: return f"Error searching for {food_name}: {str(e)}" # Custom tool for generating Ethiopian food images @tool def generate_ethiopian_food_image(food_description: str, style: str = "authentic") -> str: """Generate an authentic Ethiopian food image based on research Args: food_description: Detailed description of the food to generate style: Style of image - "authentic", "restaurant", "home-cooked" """ try: # This will use the gr1_qwen_image_fast_generate_image tool return f"Generating {style} Ethiopian food image: {food_description}" except Exception as e: return f"Error generating image: {str(e)}" final_answer = FinalAnswerTool() # Model configuration model = HfApiModel( max_tokens=2096, temperature=0.5, model_id='Qwen/Qwen2.5-Coder-32B-Instruct', custom_role_conversions=None, ) # Load prompt templates with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream) # Create the Ethiopian food agent agent = CodeAgent( model=model, tools=[search_ethiopian_food_authentic, generate_ethiopian_food_image, final_answer], max_steps=6, verbosity_level=1, grammar=None, planning_interval=None, name="ethiopian_food_image_generator", description="Generates authentic Ethiopian food images by researching exact appearance first", prompt_templates=prompt_templates ) # Launch the Gradio UI GradioUI(agent).launch()