File size: 949 Bytes
081afc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52

import os
import gradio as gr
from smolagents import CodeAgent, InferenceClientModel
from smolagents import DuckDuckGoSearchTool

# Initialize AI Agent
def create_agent():

    token = os.getenv("HF_TOKEN")

    model = InferenceClientModel(
        model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
        token=token
    )

    search_tool = DuckDuckGoSearchTool()

    agent = CodeAgent(
        tools=[search_tool],
        model=model,
        max_steps=6
    )

    return agent


# Create Alfred
agent = create_agent()


# Chat function
def chat(message, history):

    try:
        response = agent.run(message, reset=True)
        return str(response)

    except Exception as e:
        return f"Error: {str(e)}"


# Gradio interface
demo = gr.ChatInterface(
    fn=chat,
    title="Alfred - AI Research Agent",
    description="Ask Alfred questions. He can search the web and answer using AI."
)

if __name__ == "__main__":
    demo.launch()