Update main.py
Browse files
main.py
CHANGED
@@ -10,6 +10,16 @@ from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
|
10 |
from sklearn.neighbors import NearestNeighbors
|
11 |
from numpy.linalg import norm
|
12 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Define function for feature extraction
|
15 |
def feature_extraction(img_path, model):
|
@@ -39,10 +49,10 @@ def save_uploaded_file(uploaded_file):
|
|
39 |
with open(file_path, 'wb') as f:
|
40 |
f.write(uploaded_file.getbuffer())
|
41 |
st.success(f"File saved to {file_path}")
|
42 |
-
return
|
43 |
except Exception as e:
|
44 |
st.error(f"Error saving file: {e}")
|
45 |
-
return
|
46 |
|
47 |
# Function to show dashboard content
|
48 |
def show_dashboard():
|
@@ -66,16 +76,28 @@ def show_dashboard():
|
|
66 |
# File upload section
|
67 |
uploaded_file = st.file_uploader("Choose an image")
|
68 |
if uploaded_file is not None:
|
69 |
-
|
|
|
70 |
# Display the uploaded image
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
|
74 |
# Feature extraction
|
75 |
-
|
|
|
|
|
|
|
|
|
76 |
|
77 |
# Recommendation
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# Display recommended products
|
81 |
col1, col2, col3, col4, col5 = st.columns(5)
|
|
|
10 |
from sklearn.neighbors import NearestNeighbors
|
11 |
from numpy.linalg import norm
|
12 |
from chatbot import Chatbot # Assuming you have a chatbot module
|
13 |
+
import zipfile
|
14 |
+
|
15 |
+
# Define the path to the zip file and the directory to extract to
|
16 |
+
zip_file_path = 'images.zip'
|
17 |
+
extract_to = 'images'
|
18 |
+
|
19 |
+
# Check if the images directory already exists to avoid re-extracting
|
20 |
+
if not os.path.exists(extract_to):
|
21 |
+
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
22 |
+
zip_ref.extractall(extract_to)
|
23 |
|
24 |
# Define function for feature extraction
|
25 |
def feature_extraction(img_path, model):
|
|
|
49 |
with open(file_path, 'wb') as f:
|
50 |
f.write(uploaded_file.getbuffer())
|
51 |
st.success(f"File saved to {file_path}")
|
52 |
+
return file_path
|
53 |
except Exception as e:
|
54 |
st.error(f"Error saving file: {e}")
|
55 |
+
return None
|
56 |
|
57 |
# Function to show dashboard content
|
58 |
def show_dashboard():
|
|
|
76 |
# File upload section
|
77 |
uploaded_file = st.file_uploader("Choose an image")
|
78 |
if uploaded_file is not None:
|
79 |
+
file_path = save_uploaded_file(uploaded_file)
|
80 |
+
if file_path:
|
81 |
# Display the uploaded image
|
82 |
+
try:
|
83 |
+
display_image = Image.open(file_path)
|
84 |
+
st.image(display_image)
|
85 |
+
except Exception as e:
|
86 |
+
st.error(f"Error displaying uploaded image: {e}")
|
87 |
|
88 |
# Feature extraction
|
89 |
+
try:
|
90 |
+
features = feature_extraction(file_path, model)
|
91 |
+
except Exception as e:
|
92 |
+
st.error(f"Error extracting features: {e}")
|
93 |
+
return
|
94 |
|
95 |
# Recommendation
|
96 |
+
try:
|
97 |
+
indices = recommend(features, feature_list)
|
98 |
+
except Exception as e:
|
99 |
+
st.error(f"Error in recommendation: {e}")
|
100 |
+
return
|
101 |
|
102 |
# Display recommended products
|
103 |
col1, col2, col3, col4, col5 = st.columns(5)
|