Download app.py from usman045/My_Agent: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/usman045/My_Agent/resolve/main/app.py
- Command line
-
hf download hf://spaces/usman045/My_Agent/app.py
-
curl -L -o app.py https://huggingface.co/spaces/usman045/My_Agent/resolve/main/app.py
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() | |