memex-in commited on
Commit
be55beb
·
verified ·
1 Parent(s): 2af2e02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
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
- # Create an AsciiArt instance from the image file
23
- my_art = AsciiArt.from_image(image_path)
24
- # Display the ASCII art in the terminal
25
- my_art.to_terminal(columns=100, monochrome=True)
 
 
26
 
27
- if __name__ == '__main__':
28
- url = input("Enter the website URL (e.g., https://example.com): ").strip()
29
- screenshot_file = 'screenshot.png'
 
 
30
 
31
- print(f"\nCapturing screenshot of {url}...")
32
- capture_screenshot(url, screenshot_file)
33
 
34
- print("\nConverting screenshot to ASCII art:\n")
35
- convert_to_ascii(screenshot_file)
36
 
37
- # Optional: Remove the screenshot file after conversion
38
- os.remove(screenshot_file)
 
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}")