First_agent_template / Gradio_UI.py
kostas696's picture
Update Gradio_UI.py
34fc67d verified
Raw History Blame Contribute Delete
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"]