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("

✨ Interactive Blog Scraper ✨

") with gr.Row(): with gr.Column(): gr.HTML('
') 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('
') with gr.Column(): gr.HTML('
') output = gr.Textbox(label="Scraped Titles", interactive=False) copy_btn = gr.Button("Copy to Clipboard") gr.HTML('
') # 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)