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