|
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}") |
|
|