IotaCluster commited on
Commit
9b78455
·
verified ·
1 Parent(s): 178e5b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -30
app.py CHANGED
@@ -1,37 +1,29 @@
1
  import gradio as gr
2
- from selenium import webdriver
3
- from selenium.webdriver.chrome.options import Options
4
- from webdriver_manager.chrome import ChromeDriverManager
5
- import time
6
 
7
- def capture_screenshot(url):
8
- options = Options()
9
- options.add_argument("--headless")
10
- options.add_argument("--no-sandbox")
11
- options.add_argument("--disable-dev-shm-usage")
12
- options.add_argument("--window-size=1920,1080")
13
-
14
- driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
15
-
16
- screenshot_path = "screenshot.png"
17
  try:
18
- driver.get(url)
19
- time.sleep(2)
20
- driver.save_screenshot(screenshot_path)
 
 
 
21
  except Exception as e:
22
- return f"Error: {str(e)}"
23
- finally:
24
- driver.quit()
 
 
 
 
 
25
 
26
- return screenshot_path
 
 
27
 
28
- demo = gr.Interface(
29
- fn=capture_screenshot,
30
- inputs=gr.Textbox(label="Enter URL"),
31
- outputs=gr.Image(label="Screenshot"),
32
- title="Web Page Screenshot Tool",
33
- description="Enter a URL and get a screenshot using headless Chrome.",
34
- )
35
 
36
- if __name__ == "__main__":
37
- demo.launch()
 
1
  import gradio as gr
2
+ from extract import take_webdata
3
+ from PIL import Image
 
 
4
 
5
+ def visualize(url):
 
 
 
 
 
 
 
 
 
6
  try:
7
+ html_image, html_content = take_webdata(url)
8
+ if not html_content:
9
+ return None, "❌ Error: empty HTML content"
10
+ if not html_image:
11
+ return None, "❌ Error: empty image preview"
12
+ return html_image, html_content
13
  except Exception as e:
14
+ return None, f"Error: {str(e)}"
15
+
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("# 🌐 Website Content Extractor")
18
+ gr.Markdown("Enter a URL below to fetch and preview website content.")
19
+
20
+ url_input = gr.Textbox(label="Enter a URL")
21
+ submit_button = gr.Button("Proceed")
22
 
23
+ with gr.Row():
24
+ img_output = gr.Image(label="Website Preview", type="pil")
25
+ text_output = gr.Textbox(label="Website Title/Content")
26
 
27
+ submit_button.click(fn=visualize, inputs=[url_input], outputs=[img_output, text_output])
 
 
 
 
 
 
28
 
29
+ demo.launch()