Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ def take_screenshot(url):
|
|
| 14 |
wd = None
|
| 15 |
try:
|
| 16 |
wd = webdriver.Chrome(options=options)
|
| 17 |
-
wd.set_window_size(
|
| 18 |
wd.get(url)
|
| 19 |
time.sleep(5)
|
| 20 |
screenshot = wd.get_screenshot_as_png()
|
|
@@ -23,7 +23,18 @@ def take_screenshot(url):
|
|
| 23 |
print("⚠ Screenshot too small, likely error.")
|
| 24 |
return None
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
except WebDriverException as e:
|
| 29 |
print("WebDriverException:", e)
|
|
@@ -35,9 +46,9 @@ def take_screenshot(url):
|
|
| 35 |
iface = gr.Interface(
|
| 36 |
fn=take_screenshot,
|
| 37 |
inputs=gr.Textbox(label="Website URL", value="https://github.com"),
|
| 38 |
-
outputs=gr.Image(type="pil", label="Screenshot"),
|
| 39 |
title="Website Screenshot",
|
| 40 |
-
description="Takes a screenshot of the website
|
| 41 |
)
|
| 42 |
|
| 43 |
iface.launch()
|
|
|
|
| 14 |
wd = None
|
| 15 |
try:
|
| 16 |
wd = webdriver.Chrome(options=options)
|
| 17 |
+
wd.set_window_size(1920, 1080) # Set window size to 1920x1080
|
| 18 |
wd.get(url)
|
| 19 |
time.sleep(5)
|
| 20 |
screenshot = wd.get_screenshot_as_png()
|
|
|
|
| 23 |
print("⚠ Screenshot too small, likely error.")
|
| 24 |
return None
|
| 25 |
|
| 26 |
+
image = Image.open(BytesIO(screenshot))
|
| 27 |
+
|
| 28 |
+
# Center crop to 900x900
|
| 29 |
+
width, height = image.size
|
| 30 |
+
crop_size = 900
|
| 31 |
+
left = (width - crop_size) // 2
|
| 32 |
+
top = (height - crop_size) // 2
|
| 33 |
+
right = left + crop_size
|
| 34 |
+
bottom = top + crop_size
|
| 35 |
+
cropped_image = image.crop((left, top, right, bottom))
|
| 36 |
+
|
| 37 |
+
return cropped_image
|
| 38 |
|
| 39 |
except WebDriverException as e:
|
| 40 |
print("WebDriverException:", e)
|
|
|
|
| 46 |
iface = gr.Interface(
|
| 47 |
fn=take_screenshot,
|
| 48 |
inputs=gr.Textbox(label="Website URL", value="https://github.com"),
|
| 49 |
+
outputs=gr.Image(type="pil", label="Cropped Screenshot"),
|
| 50 |
title="Website Screenshot",
|
| 51 |
+
description="Takes a 1920x1080 screenshot of the website, center-cropped to 900x900."
|
| 52 |
)
|
| 53 |
|
| 54 |
iface.launch()
|