File size: 1,307 Bytes
9305c51
be55beb
9305c51
 
ded13e3
9305c51
 
 
 
 
be55beb
9305c51
 
 
 
 
 
 
 
be55beb
 
 
 
 
 
9305c51
be55beb
 
 
 
 
9305c51
be55beb
 
9305c51
be55beb
 
9305c51
be55beb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import streamlit as st
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from ascii_magic import AsciiArt

def capture_screenshot(url, output_path='screenshot.png'):
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--window-size=1920,1080')

    driver = webdriver.Chrome(options=chrome_options)
    driver.get(url)
    driver.save_screenshot(output_path)
    driver.quit()

def convert_to_ascii(image_path):
    ascii_art = AsciiArt.from_image(image_path)
    return ascii_art.to_string(columns=100, monochrome=True)

st.title("ASCII Web Screenshot Viewer")

url = st.text_input("Enter a website URL:", "https://example.com")

if st.button("Generate ASCII Screenshot"):
    try:
        screenshot_file = "screenshot.png"
        st.write("Capturing website screenshot...")
        capture_screenshot(url, screenshot_file)

        st.write("Converting to ASCII art...")
        ascii_output = convert_to_ascii(screenshot_file)

        st.text_area("ASCII Art Output", ascii_output, height=600)
        os.remove(screenshot_file)

    except Exception as e:
        st.error(f"An error occurred: {e}")