Spaces:
Sleeping
Sleeping
Download Gradio_UI.py from kostas696/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/kostas696/First_agent_template/resolve/main/Gradio_UI.py
- Command line
-
hf download hf://spaces/kostas696/First_agent_template/Gradio_UI.py
-
curl -L -o Gradio_UI.py https://huggingface.co/spaces/kostas696/First_agent_template/resolve/main/Gradio_UI.py
1.19 kB
| import gradio as gr | |
| class GradioUI: | |
| """A class to handle the web scraping Gradio UI""" | |
| def __init__(self, agent): | |
| """Initialize with the provided agent""" | |
| self.agent = agent | |
| def launch(self): | |
| """Sets up the Gradio UI for web scraping.""" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🕵️ Web Scraper Tool") | |
| gr.Markdown("Enter a URL and select an HTML element to scrape.") | |
| url_input = gr.Textbox(label="Website URL", placeholder="Enter URL (e.g., https://example.com)") | |
| element_input = gr.Dropdown(["p", "h1", "h2", "div", "a", "span"], label="HTML Element", value="p") | |
| scrape_button = gr.Button("Scrape") | |
| output_text = gr.Textbox(label="Scraped Content", interactive=False) | |
| # Call agent to execute the web scraping | |
| scrape_button.click(fn=self.scrape_website, inputs=[url_input, element_input], outputs=output_text) | |
| demo.launch() | |
| def scrape_website(self, url, element): | |
| """Helper function to call the agent for web scraping.""" | |
| return self.agent.run(f"Scrape {element} elements from {url}") | |
| __all__ = ["GradioUI"] |