import os import yaml import gradio as gr from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool from tools.final_answer import FinalAnswerTool # 1. Define your custom tool @tool def get_daily_word() -> str: """A tool that returns a motivational word for English learners.""" import random words = ["Persistence", "Eloquence", "Clarity", "Resilience", "Impact"] return f"Today's word is: {random.choice(words)}" final_answer = FinalAnswerTool() # 2. Setup the Model model = HfApiModel( model_id='Qwen/Qwen2.5-Coder-32B-Instruct', token=os.getenv("HF_TOKEN") ) # 3. Load prompts and initialize Agent with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream) agent = CodeAgent( model=model, tools=[final_answer, get_daily_word, DuckDuckGoSearchTool()], max_steps=6, prompt_templates=prompt_templates ) # 4. Custom UI Logic (Safe for Gradio 6.0) def answer_task(message, history): # This runs the agent and returns the string response response = agent.run(message) return response demo = gr.ChatInterface( fn=answer_task, title="Hugging Face Agentic AI Project", description="Ask me for a daily word or to search the web!" ) if __name__ == "__main__": demo.launch()