Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
| 5 |
-
import time
|
| 6 |
|
| 7 |
-
def
|
| 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 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
except Exception as e:
|
| 22 |
-
return f"Error: {str(e)}"
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 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 |
-
|
| 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()
|
|
|