Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,40 @@
|
|
1 |
import os
|
|
|
2 |
from selenium import webdriver
|
3 |
from selenium.webdriver.chrome.options import Options
|
4 |
from ascii_magic import AsciiArt
|
5 |
|
6 |
def capture_screenshot(url, output_path='screenshot.png'):
|
7 |
-
# Set up headless Chrome
|
8 |
chrome_options = Options()
|
9 |
chrome_options.add_argument('--headless')
|
10 |
chrome_options.add_argument('--disable-gpu')
|
|
|
11 |
chrome_options.add_argument('--window-size=1920,1080')
|
12 |
|
13 |
-
# Initialize WebDriver
|
14 |
driver = webdriver.Chrome(options=chrome_options)
|
15 |
driver.get(url)
|
16 |
-
|
17 |
-
# Save screenshot
|
18 |
driver.save_screenshot(output_path)
|
19 |
driver.quit()
|
20 |
|
21 |
def convert_to_ascii(image_path):
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
if
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
|
|
1 |
import os
|
2 |
+
import streamlit as st
|
3 |
from selenium import webdriver
|
4 |
from selenium.webdriver.chrome.options import Options
|
5 |
from ascii_magic import AsciiArt
|
6 |
|
7 |
def capture_screenshot(url, output_path='screenshot.png'):
|
|
|
8 |
chrome_options = Options()
|
9 |
chrome_options.add_argument('--headless')
|
10 |
chrome_options.add_argument('--disable-gpu')
|
11 |
+
chrome_options.add_argument('--no-sandbox')
|
12 |
chrome_options.add_argument('--window-size=1920,1080')
|
13 |
|
|
|
14 |
driver = webdriver.Chrome(options=chrome_options)
|
15 |
driver.get(url)
|
|
|
|
|
16 |
driver.save_screenshot(output_path)
|
17 |
driver.quit()
|
18 |
|
19 |
def convert_to_ascii(image_path):
|
20 |
+
ascii_art = AsciiArt.from_image(image_path)
|
21 |
+
return ascii_art.to_string(columns=100, monochrome=True)
|
22 |
+
|
23 |
+
st.title("ASCII Web Screenshot Viewer")
|
24 |
+
|
25 |
+
url = st.text_input("Enter a website URL:", "https://example.com")
|
26 |
|
27 |
+
if st.button("Generate ASCII Screenshot"):
|
28 |
+
try:
|
29 |
+
screenshot_file = "screenshot.png"
|
30 |
+
st.write("Capturing website screenshot...")
|
31 |
+
capture_screenshot(url, screenshot_file)
|
32 |
|
33 |
+
st.write("Converting to ASCII art...")
|
34 |
+
ascii_output = convert_to_ascii(screenshot_file)
|
35 |
|
36 |
+
st.text_area("ASCII Art Output", ascii_output, height=600)
|
37 |
+
os.remove(screenshot_file)
|
38 |
|
39 |
+
except Exception as e:
|
40 |
+
st.error(f"An error occurred: {e}")
|