Spaces:
Sleeping
Sleeping
Download Gradio_UI.py from Idealcom/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/Idealcom/Final_Assignment_Template/resolve/main/Gradio_UI.py
- Command line
-
hf download hf://spaces/Idealcom/Final_Assignment_Template/Gradio_UI.py
-
curl -L -o Gradio_UI.py https://huggingface.co/spaces/Idealcom/Final_Assignment_Template/resolve/main/Gradio_UI.py
1.48 kB
| import gradio as gr | |
| from typing import Optional | |
| class GradioUI: | |
| """Gradio UI wrapper for smolagents CodeAgent""" | |
| def __init__(self, agent): | |
| self.agent = agent | |
| def run_agent(self, query: str) -> str: | |
| """Execute agent and return response""" | |
| try: | |
| result = self.agent.run(query) | |
| return str(result) | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| def launch(self, server_name: str = "0.0.0.0", server_port: int = 7860, share: bool = False): | |
| """Launch Gradio interface""" | |
| interface = gr.Interface( | |
| fn=self.run_agent, | |
| inputs=gr.Textbox( | |
| label="Your Question", | |
| lines=3, | |
| placeholder="Ask me anything..." | |
| ), | |
| outputs=gr.Textbox( | |
| label="Agent Response", | |
| lines=5 | |
| ), | |
| title="GAIA Agent - Smolagents", | |
| description="🤖 AI Agent powered by smolagents | Solves complex tasks using web search and reasoning", | |
| examples=[ | |
| ["What is the capital of France?"], | |
| ["Find information about artificial intelligence"], | |
| ["How many days are in February 2025?"], | |
| ], | |
| theme=gr.themes.Soft() | |
| ) | |
| interface.launch( | |
| server_name=server_name, | |
| server_port=server_port, | |
| share=share | |
| ) | |