simran40 commited on
Commit
fd7d179
·
verified ·
1 Parent(s): b2249a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -40
app.py CHANGED
@@ -1,75 +1,96 @@
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()
 
 
1
  import gradio as gr
2
+ from scraper import scrape_blog # Your scraper function
3
 
4
+ # Function to scrape multiple tags
5
+ def scrape(url, tags):
6
  if not url:
7
  return "⚠️ Please enter a valid URL"
8
+ tags_list = [t.strip() for t in tags.split(",") if t.strip()]
9
+ all_data = []
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 set tag from button
17
  def set_tag(tag):
18
  return tag
19
 
20
+ # Gradio Blocks with glass effect
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.15);
33
+ backdrop-filter: blur(20px);
34
+ border-radius: 25px;
35
+ padding: 25px;
36
+ margin: 15px 0;
37
+ box-shadow: 0 8px 32px 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: 12px !important;
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>✨ Interactive Blog Scraper ✨</h1>")
61
 
62
  with gr.Row():
63
  with gr.Column():
64
+ gr.HTML('<div class="glass-card">')
65
+ url_input = gr.Textbox(label="Enter Blog URL", placeholder="https://example.com")
66
+ tag_input = gr.Textbox(label="Selected HTML Tag(s)", value="h2")
67
+
68
+ with gr.Row():
69
+ h1_btn = gr.Button("h1")
70
+ h2_btn = gr.Button("h2")
71
+ h3_btn = gr.Button("h3")
72
+ all_btn = gr.Button("h1,h2,h3")
73
+
74
+ scrape_btn = gr.Button("Scrape Blog")
75
+ gr.HTML('</div>')
76
+
77
  with gr.Column():
78
+ gr.HTML('<div class="glass-card output-box">')
79
+ output = gr.Textbox(label="Scraped Titles", interactive=False)
80
+ copy_btn = gr.Button("Copy to Clipboard")
81
+ gr.HTML('</div>')
82
 
83
+ # Button actions to set tag
84
+ h1_btn.click(set_tag, inputs=[], outputs=tag_input, args=["h1"])
85
+ h2_btn.click(set_tag, inputs=[], outputs=tag_input, args=["h2"])
86
+ h3_btn.click(set_tag, inputs=[], outputs=tag_input, args=["h3"])
87
+ all_btn.click(set_tag, inputs=[], outputs=tag_input, args=["h1,h2,h3"])
88
 
89
  # Scrape button click
90
  scrape_btn.click(scrape, inputs=[url_input, tag_input], outputs=output)
91
 
92
+ # Copy to clipboard
93
  copy_btn.click(lambda x: x, inputs=output, outputs=None)
94
 
95
+ # Launch app
96
+ demo.launch(server_name="0.0.0.0", server_port=5000)