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()