Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,7 @@ import numpy as np
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
-
from
|
8 |
-
from selenium.webdriver.chrome.service import Service
|
9 |
-
from selenium.webdriver.common.by import By
|
10 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
11 |
-
import time
|
12 |
import pandas as pd
|
13 |
import base64
|
14 |
|
@@ -38,23 +34,10 @@ def run_inference(interpreter, input_data):
|
|
38 |
return output_data_shopping_intent, output_data_sensitive
|
39 |
|
40 |
def fetch_images_from_url(url):
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
options.add_argument('--disable-gpu')
|
46 |
-
|
47 |
-
service = Service(ChromeDriverManager().install())
|
48 |
-
driver = webdriver.Chrome(service=service, options=options)
|
49 |
-
driver.get(url)
|
50 |
-
|
51 |
-
# Give the page some time to load and execute JavaScript
|
52 |
-
time.sleep(10)
|
53 |
-
|
54 |
-
images = driver.find_elements(By.TAG_NAME, 'img')
|
55 |
-
img_urls = [img.get_attribute('src') for img in images if img.get_attribute('src')]
|
56 |
-
|
57 |
-
driver.quit()
|
58 |
return img_urls
|
59 |
|
60 |
def image_to_base64(image):
|
@@ -64,8 +47,8 @@ def image_to_base64(image):
|
|
64 |
|
65 |
def main():
|
66 |
st.set_page_config(layout="wide")
|
67 |
-
st.title("
|
68 |
-
st.write("Enter a URL to fetch and classify all images on the page.")
|
69 |
|
70 |
model_path = "model.tflite"
|
71 |
url = st.text_input("Enter URL")
|
@@ -108,12 +91,7 @@ def main():
|
|
108 |
df = pd.DataFrame(data)
|
109 |
|
110 |
# Configure DataFrame display with images, URLs, and classifications
|
111 |
-
st.
|
112 |
-
"Thumbnail": st.column_config.ImageColumn("Thumbnail", help="Image thumbnails"),
|
113 |
-
"URL": st.column_config.LinkColumn("URL"),
|
114 |
-
"Shopping Intent": st.column_config.BarChartColumn("Shopping Intent", width="small"),
|
115 |
-
"Sensitivity": st.column_config.BarChartColumn("Sensitivity", width="small")
|
116 |
-
})
|
117 |
|
118 |
# Display errors in an expandable section
|
119 |
if errors:
|
@@ -122,4 +100,4 @@ def main():
|
|
122 |
st.write(error)
|
123 |
|
124 |
if __name__ == "__main__":
|
125 |
-
main()
|
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
+
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
8 |
import pandas as pd
|
9 |
import base64
|
10 |
|
|
|
34 |
return output_data_shopping_intent, output_data_sensitive
|
35 |
|
36 |
def fetch_images_from_url(url):
|
37 |
+
response = requests.get(url)
|
38 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
39 |
+
img_tags = soup.find_all('img')
|
40 |
+
img_urls = [img['src'] for img in img_tags if 'src' in img.attrs]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
return img_urls
|
42 |
|
43 |
def image_to_base64(image):
|
|
|
47 |
|
48 |
def main():
|
49 |
st.set_page_config(layout="wide")
|
50 |
+
st.title("Shopping Intent Classification - SEO by DEJAN")
|
51 |
+
st.write("Enter a URL to fetch and classify all images on the page. Javascript-based website scraping currently unsupported.")
|
52 |
|
53 |
model_path = "model.tflite"
|
54 |
url = st.text_input("Enter URL")
|
|
|
91 |
df = pd.DataFrame(data)
|
92 |
|
93 |
# Configure DataFrame display with images, URLs, and classifications
|
94 |
+
st.dataframe(df) # Use dataframe for simple display
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# Display errors in an expandable section
|
97 |
if errors:
|
|
|
100 |
st.write(error)
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
+
main()
|