Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
import streamlit as st
|
3 |
from selenium import webdriver
|
4 |
from selenium.webdriver.chrome.options import Options
|
5 |
-
from
|
6 |
|
7 |
# Function to capture a screenshot of a webpage
|
8 |
def capture_screenshot(url, output_path='screenshot.png'):
|
@@ -19,33 +19,21 @@ def capture_screenshot(url, output_path='screenshot.png'):
|
|
19 |
finally:
|
20 |
driver.quit() # Ensure the driver is closed even if an error occurs
|
21 |
|
22 |
-
# Function to convert an image to ASCII art
|
23 |
-
def convert_to_ascii(image_path):
|
24 |
-
try:
|
25 |
-
# Create ASCII art from the image
|
26 |
-
ascii_art = AsciiArt.from_image(image_path) # Create the AsciiArt object
|
27 |
-
return ascii_art.get_ascii() # Use the get_ascii() method to get the ASCII representation
|
28 |
-
except Exception as e:
|
29 |
-
raise Exception(f"Failed to convert image to ASCII: {e}")
|
30 |
-
|
31 |
# Streamlit app layout
|
32 |
-
st.title("
|
33 |
|
34 |
# Input field for URL
|
35 |
url = st.text_input("Enter a website URL:", "https://example.com")
|
36 |
|
37 |
-
# Button to trigger the screenshot
|
38 |
-
if st.button("Generate
|
39 |
try:
|
40 |
screenshot_file = "screenshot.png"
|
41 |
st.write("Capturing website screenshot...")
|
42 |
capture_screenshot(url.strip('"')) # Strip any extra quotes from the URL
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
# Display ASCII art in a text area
|
48 |
-
st.text_area("ASCII Art Output", ascii_output, height=600)
|
49 |
|
50 |
except Exception as e:
|
51 |
st.error(f"An error occurred: {e}")
|
|
|
2 |
import streamlit as st
|
3 |
from selenium import webdriver
|
4 |
from selenium.webdriver.chrome.options import Options
|
5 |
+
from PIL import Image
|
6 |
|
7 |
# Function to capture a screenshot of a webpage
|
8 |
def capture_screenshot(url, output_path='screenshot.png'):
|
|
|
19 |
finally:
|
20 |
driver.quit() # Ensure the driver is closed even if an error occurs
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Streamlit app layout
|
23 |
+
st.title("Web Screenshot Viewer")
|
24 |
|
25 |
# Input field for URL
|
26 |
url = st.text_input("Enter a website URL:", "https://example.com")
|
27 |
|
28 |
+
# Button to trigger the screenshot process
|
29 |
+
if st.button("Generate Screenshot"):
|
30 |
try:
|
31 |
screenshot_file = "screenshot.png"
|
32 |
st.write("Capturing website screenshot...")
|
33 |
capture_screenshot(url.strip('"')) # Strip any extra quotes from the URL
|
34 |
|
35 |
+
# Display the screenshot in the Streamlit app
|
36 |
+
st.image(screenshot_file, caption='Screenshot of the webpage', use_column_width=True)
|
|
|
|
|
|
|
37 |
|
38 |
except Exception as e:
|
39 |
st.error(f"An error occurred: {e}")
|