Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,96 +1,75 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from scraper import scrape_blog
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
def scrape(url,
|
| 6 |
if not url:
|
| 7 |
return "⚠️ Please enter a valid URL"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
for tag in tags_list:
|
| 11 |
-
data = scrape_blog(url, tag)
|
| 12 |
-
if data:
|
| 13 |
-
all_data.append(f"Results for <{tag}>:\n" + "\n".join(data))
|
| 14 |
-
return "\n\n".join(all_data) if all_data else "No data found!"
|
| 15 |
|
| 16 |
-
# Function to
|
| 17 |
def set_tag(tag):
|
| 18 |
return tag
|
| 19 |
|
| 20 |
-
# Gradio
|
| 21 |
with gr.Blocks(css="""
|
| 22 |
body {
|
| 23 |
background: linear-gradient(135deg, #89f7fe, #66a6ff);
|
| 24 |
font-family: 'Arial', sans-serif;
|
| 25 |
}
|
| 26 |
-
h1 {
|
| 27 |
-
color: #fff;
|
| 28 |
-
text-align: center;
|
| 29 |
-
text-shadow: 1px 1px 8px rgba(0,0,0,0.3);
|
| 30 |
-
}
|
| 31 |
.glass-card {
|
| 32 |
-
background: rgba(255, 255, 255, 0.
|
| 33 |
-
backdrop-filter: blur(
|
| 34 |
-
border-radius:
|
| 35 |
-
padding:
|
| 36 |
-
margin: 10px 0;
|
| 37 |
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
| 38 |
border: 1px solid rgba(255, 255, 255, 0.18);
|
| 39 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
.gr-button {
|
| 41 |
background: rgba(255, 255, 255, 0.3) !important;
|
| 42 |
color: #000 !important;
|
| 43 |
font-weight: bold;
|
| 44 |
-
border-radius:
|
| 45 |
margin: 5px;
|
| 46 |
-
transition: 0.3s;
|
| 47 |
-
}
|
| 48 |
-
.gr-button:hover {
|
| 49 |
-
background: rgba(255, 255, 255, 0.6) !important;
|
| 50 |
-
color: #222 !important;
|
| 51 |
-
transform: scale(1.05);
|
| 52 |
-
}
|
| 53 |
-
.output-box {
|
| 54 |
-
max-height: 400px;
|
| 55 |
-
overflow-y: auto;
|
| 56 |
-
white-space: pre-wrap;
|
| 57 |
}
|
| 58 |
""") as demo:
|
| 59 |
|
| 60 |
-
gr.HTML("<h1>✨
|
| 61 |
|
| 62 |
with gr.Row():
|
| 63 |
with gr.Column():
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
gr.HTML("</div>")
|
| 77 |
-
|
| 78 |
with gr.Column():
|
| 79 |
-
gr.
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
gr.HTML('</div>')
|
| 83 |
|
| 84 |
-
# Tag
|
| 85 |
-
h1_btn.click(set_tag, inputs=[], outputs=tag_input,
|
| 86 |
-
h2_btn.click(set_tag, inputs=[], outputs=tag_input
|
| 87 |
-
h3_btn.click(set_tag, inputs=[], outputs=tag_input
|
| 88 |
-
all_btn.click(set_tag, inputs=[], outputs=tag_input, args=["h1,h2,h3"])
|
| 89 |
|
| 90 |
-
# Scrape button
|
| 91 |
scrape_btn.click(scrape, inputs=[url_input, tag_input], outputs=output)
|
| 92 |
|
| 93 |
-
# Copy button
|
| 94 |
copy_btn.click(lambda x: x, inputs=output, outputs=None)
|
| 95 |
|
| 96 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from scraper import scrape_blog
|
| 3 |
|
| 4 |
+
# Function to scrape
|
| 5 |
+
def scrape(url, tag='h2'):
|
| 6 |
if not url:
|
| 7 |
return "⚠️ Please enter a valid URL"
|
| 8 |
+
data = scrape_blog(url, tag)
|
| 9 |
+
return "\n".join(data) if data else "No data found!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Function to update tag when button clicked
|
| 12 |
def set_tag(tag):
|
| 13 |
return tag
|
| 14 |
|
| 15 |
+
# Gradio Blocks with creative glass effect
|
| 16 |
with gr.Blocks(css="""
|
| 17 |
body {
|
| 18 |
background: linear-gradient(135deg, #89f7fe, #66a6ff);
|
| 19 |
font-family: 'Arial', sans-serif;
|
| 20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
.glass-card {
|
| 22 |
+
background: rgba(255, 255, 255, 0.2);
|
| 23 |
+
backdrop-filter: blur(15px);
|
| 24 |
+
border-radius: 20px;
|
| 25 |
+
padding: 20px;
|
|
|
|
| 26 |
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
| 27 |
border: 1px solid rgba(255, 255, 255, 0.18);
|
| 28 |
}
|
| 29 |
+
h1 {
|
| 30 |
+
color: #fff;
|
| 31 |
+
text-align: center;
|
| 32 |
+
text-shadow: 1px 1px 5px rgba(0,0,0,0.3);
|
| 33 |
+
}
|
| 34 |
.gr-button {
|
| 35 |
background: rgba(255, 255, 255, 0.3) !important;
|
| 36 |
color: #000 !important;
|
| 37 |
font-weight: bold;
|
| 38 |
+
border-radius: 10px !important;
|
| 39 |
margin: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
""") as demo:
|
| 42 |
|
| 43 |
+
gr.HTML("<h1>✨ Creative Blog Scraper ✨</h1>")
|
| 44 |
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column():
|
| 47 |
+
with gr.Box(css_class="glass-card"):
|
| 48 |
+
url_input = gr.Textbox(label="Enter Blog URL", placeholder="https://example.com")
|
| 49 |
+
tag_input = gr.Textbox(label="Selected HTML Tag", value="h2")
|
| 50 |
+
|
| 51 |
+
# Tag buttons
|
| 52 |
+
with gr.Row():
|
| 53 |
+
h1_btn = gr.Button("h1")
|
| 54 |
+
h2_btn = gr.Button("h2")
|
| 55 |
+
h3_btn = gr.Button("h3")
|
| 56 |
+
|
| 57 |
+
scrape_btn = gr.Button("Scrape Blog")
|
| 58 |
+
|
|
|
|
|
|
|
| 59 |
with gr.Column():
|
| 60 |
+
with gr.Box(css_class="glass-card"):
|
| 61 |
+
output = gr.Textbox(label="Scraped Titles", interactive=False)
|
| 62 |
+
copy_btn = gr.Button("Copy to Clipboard")
|
|
|
|
| 63 |
|
| 64 |
+
# Tag button clicks
|
| 65 |
+
h1_btn.click(set_tag, inputs=[], outputs=tag_input, api_name=None).then(lambda: "h1", inputs=None, outputs=tag_input)
|
| 66 |
+
h2_btn.click(set_tag, inputs=[], outputs=tag_input).then(lambda: "h2", inputs=None, outputs=tag_input)
|
| 67 |
+
h3_btn.click(set_tag, inputs=[], outputs=tag_input).then(lambda: "h3", inputs=None, outputs=tag_input)
|
|
|
|
| 68 |
|
| 69 |
+
# Scrape button click
|
| 70 |
scrape_btn.click(scrape, inputs=[url_input, tag_input], outputs=output)
|
| 71 |
|
| 72 |
+
# Copy button (Gradio 4.10+ supports this via JS)
|
| 73 |
copy_btn.click(lambda x: x, inputs=output, outputs=None)
|
| 74 |
|
| 75 |
demo.launch()
|