Spaces:
Sleeping
Sleeping
theekshanamadumal
commited on
Commit
•
b6e91ad
1
Parent(s):
edbb3ae
init
Browse files- app.py +35 -0
- extract.py +23 -0
- packages.txt +1 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from extract import take_screenshot
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
def main():
|
6 |
+
st.title("Website Visualizer")
|
7 |
+
|
8 |
+
# Get website URL from user input
|
9 |
+
url = st.text_input("Enter a URL:", "")
|
10 |
+
if st.button("Proceed"):
|
11 |
+
if not url:
|
12 |
+
st.warning("URL is empty.")
|
13 |
+
else:
|
14 |
+
visualize(url)
|
15 |
+
|
16 |
+
|
17 |
+
def visualize(url):
|
18 |
+
try:
|
19 |
+
# Fetch and display the website content
|
20 |
+
with st.spinner("loading website data ..."):
|
21 |
+
# innerHTML = get_innerHTML(url)
|
22 |
+
innerHTML = take_screenshot(url)
|
23 |
+
st.subheader("Website preview:")
|
24 |
+
if innerHTML:
|
25 |
+
st.Image(innerHTML)
|
26 |
+
else:
|
27 |
+
st.error("Error: empty html")
|
28 |
+
|
29 |
+
except Exception as e:
|
30 |
+
st.error(f"Error: {e}")
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
main()
|
extract.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from selenium import webdriver
|
2 |
+
from selenium.common.exceptions import WebDriverException
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
def take_screenshot(url):
|
6 |
+
options = webdriver.ChromeOptions()
|
7 |
+
options.add_argument('--headless')
|
8 |
+
options.add_argument('--no-sandbox')
|
9 |
+
options.add_argument('--disable-dev-shm-usage')
|
10 |
+
|
11 |
+
try:
|
12 |
+
wd = webdriver.Chrome(options=options)
|
13 |
+
wd.set_window_size(1080, 720) # Adjust the window size here
|
14 |
+
wd.get(url)
|
15 |
+
wd.implicitly_wait(10)
|
16 |
+
screenshot = wd.get_screenshot_as_png()
|
17 |
+
except WebDriverException as e:
|
18 |
+
return Image.new('RGB', (1, 1))
|
19 |
+
finally:
|
20 |
+
if wd:
|
21 |
+
wd.quit()
|
22 |
+
|
23 |
+
return Image.open(BytesIO(screenshot))
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
chromium-driver
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
selenium >=4.0.0, < 5.0.0
|
2 |
+
streamlit
|
3 |
+
Pillow>=8.3.1,<9.0
|