Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel | |
| from datetime import datetime | |
| # 1. Setup the "Brain" | |
| # This uses the HF API so you don't have to build llama-cpp. | |
| # It's faster and handles tools much better. | |
| model = HfApiModel(model_id="meta-llama/Llama-3.2-3B-Instruct") | |
| # 2. Define Custom Tools | |
| def get_current_info(): | |
| """A tool that fetches the exact current date and time.""" | |
| now = datetime.now() | |
| return f"Current Date: {now.strftime('%A, %B %d, %Y')}\nTime: {now.strftime('%H:%M:%S')}" | |
| # 3. Create the Agent | |
| agent = CodeAgent( | |
| tools=[ | |
| DuckDuckGoSearchTool(), # For News and Website visiting | |
| get_current_info # For Current Date | |
| ], | |
| model=model, | |
| add_base_tools=True | |
| ) | |
| # 4. Gradio Interface Setup | |
| def interact(message, history): | |
| # This runs the agentic logic: Search -> Think -> Answer | |
| result = agent.run(message) | |
| return str(result) | |
| demo = gr.ChatInterface( | |
| fn=interact, | |
| title="๐ Super-Smart AI Agent", | |
| description="I can visit websites, check the news, and I know exactly what day it is.", | |
| examples=["What's the latest news in tech today?", "What is the date today?", "Visit google.com and tell me what's trending."] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |