Spaces:
Sleeping
Sleeping
Upload main files
Browse files- Images_features2.pkl +3 -0
- app.py +73 -0
- filenames2.pkl +3 -0
- model.h5 +3 -0
- requirements.txt +3 -0
Images_features2.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2a707cde72a062b48a907de8ed64aa0667d879259f9f0b8f1ec8ed653c6ce9f4
|
| 3 |
+
size 365621870
|
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle as pkl
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from sklearn.neighbors import NearestNeighbors
|
| 5 |
+
from tensorflow.keras.models import load_model
|
| 6 |
+
from tensorflow.keras.applications.resnet50 import preprocess_input
|
| 7 |
+
from tensorflow.keras.preprocessing import image
|
| 8 |
+
import os
|
| 9 |
+
from numpy.linalg import norm
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
# Load necessary files and model
|
| 13 |
+
filenames = pkl.load(open('filenames2.pkl', 'rb'))
|
| 14 |
+
Image_features = pkl.load(open('Images_features2.pkl', 'rb'))
|
| 15 |
+
neighbors = NearestNeighbors(n_neighbors=6, algorithm='brute', metric='euclidean')
|
| 16 |
+
neighbors.fit(Image_features)
|
| 17 |
+
model = load_model('model.h5')
|
| 18 |
+
|
| 19 |
+
# Feature extraction function
|
| 20 |
+
def extract_features_from_images(image_path, model):
|
| 21 |
+
img = image.load_img(image_path, target_size=(224, 224))
|
| 22 |
+
img_array = image.img_to_array(img)
|
| 23 |
+
img_expand_dim = np.expand_dims(img_array, axis=0)
|
| 24 |
+
img_preprocess = preprocess_input(img_expand_dim)
|
| 25 |
+
result = model.predict(img_preprocess).flatten()
|
| 26 |
+
norm_result = result / norm(result)
|
| 27 |
+
return norm_result
|
| 28 |
+
|
| 29 |
+
# Custom CSS for background and title
|
| 30 |
+
st.markdown(
|
| 31 |
+
"""
|
| 32 |
+
<style>
|
| 33 |
+
body {
|
| 34 |
+
background-color: #f0f8ff; /* Soft light blue background */
|
| 35 |
+
}
|
| 36 |
+
.title {
|
| 37 |
+
color: #1f7a8c; /* Teal color */
|
| 38 |
+
font-family: 'Arial Black', sans-serif;
|
| 39 |
+
text-align: center;
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
+
""",
|
| 43 |
+
unsafe_allow_html=True,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Streamlit UI
|
| 47 |
+
st.markdown('<h1 class="title">Fashion Deep Learning Classification 👗</h1>', unsafe_allow_html=True)
|
| 48 |
+
st.write('Upload a clothing image, and the model recommends similar products.')
|
| 49 |
+
|
| 50 |
+
file = st.file_uploader('Upload an Image', type=['jpg', 'jpeg', 'png'])
|
| 51 |
+
|
| 52 |
+
if file is not None:
|
| 53 |
+
# Display uploaded image with reduced size
|
| 54 |
+
img = Image.open(file)
|
| 55 |
+
st.image(img, caption='Uploaded Image', width=200, use_column_width=False)
|
| 56 |
+
|
| 57 |
+
# Extract features from the uploaded image
|
| 58 |
+
input_image = extract_features_from_images(file, model)
|
| 59 |
+
|
| 60 |
+
# Get recommendations
|
| 61 |
+
distance, indices = neighbors.kneighbors([input_image])
|
| 62 |
+
st.subheader("Recommended Products:")
|
| 63 |
+
|
| 64 |
+
# Display recommendations in a grid layout
|
| 65 |
+
cols = st.columns(3) # 3 images per row
|
| 66 |
+
for i, idx in enumerate(indices[0]):
|
| 67 |
+
product_path = filenames[idx]
|
| 68 |
+
st.write(product_path)
|
| 69 |
+
product_image = Image.open(product_path)
|
| 70 |
+
|
| 71 |
+
# Assign columns dynamically
|
| 72 |
+
with cols[i % 3]:
|
| 73 |
+
st.image(product_image, caption=f"Product {i + 1}", use_column_width=True)
|
filenames2.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f7076602ce29da942074fab43bd8af025e5f0f7fe3ec5b7ed0166bd15f8d212b
|
| 3 |
+
size 837463
|
model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7cf01a6bcea34afc501604243ab531ae715c4ffed4d9d974041fc0751df909b4
|
| 3 |
+
size 94737040
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|
| 3 |
+
scikit-learn
|