My_Agent / app.py
usman045's picture
Create app.py
081afc7 verified
Raw History Blame Contribute Delete
949 Bytes
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()