File size: 1,293 Bytes
116418f
b9890ed
116418f
 
b9890ed
 
 
 
116418f
b9890ed
 
 
 
 
116418f
b9890ed
116418f
b9890ed
 
 
 
 
116418f
 
 
b9890ed
 
 
 
 
 
 
 
 
 
 
 
116418f
b9890ed
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()