Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,23 @@
|
|
| 1 |
-
|
| 2 |
-
from scraper import scrape_blog
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from scraper import scrape_blog # your existing scraper function
|
| 3 |
|
| 4 |
+
# Define a function to scrape and return results
|
| 5 |
+
def scrape(url, tag='h2'):
|
| 6 |
+
data = scrape_blog(url, tag)
|
| 7 |
+
# Join the results into a string for display in Gradio
|
| 8 |
+
return "\n".join(data)
|
| 9 |
|
| 10 |
+
# Create Gradio interface
|
| 11 |
+
iface = gr.Interface(
|
| 12 |
+
fn=scrape,
|
| 13 |
+
inputs=[
|
| 14 |
+
gr.Textbox(label="Enter URL"),
|
| 15 |
+
gr.Textbox(label="Enter HTML Tag (default: h2)", value="h2")
|
| 16 |
+
],
|
| 17 |
+
outputs=gr.Textbox(label="Scraped Titles"),
|
| 18 |
+
title="Blog Scraper",
|
| 19 |
+
description="Enter a URL and an HTML tag to scrape titles or headings from a blog."
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
# Launch the interface
|
| 23 |
+
iface.launch()
|