Spaces:
Sleeping
Sleeping
File size: 5,197 Bytes
bce400a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import streamlit as st
import os
from PIL import Image
import numpy as np
import pickle
import tensorflow
import pandas as pd
from tensorflow.keras.preprocessing import image
from tensorflow.keras.layers import GlobalMaxPooling2D
from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input
from sklearn.neighbors import NearestNeighbors
from numpy.linalg import norm
feature_list = np.array(pickle.load(open('embedding_large.pkl','rb')))
# print(feature_list)
filenames = pd.read_pickle('filenames_large.pkl')
# print(filenames)
feature_list_myntra = np.array(pickle.load(open('embedding_myntra.pkl','rb')))
# print(feature_list)
filenames_myntra = pd.read_pickle('filenames_myntra.pkl')
model = ResNet50(weights='imagenet',include_top=False,input_shape=(224,224,3))
model.trainable = False
model = tensorflow.keras.Sequential([
model,
GlobalMaxPooling2D()
])
st.title('Fashion Recommender System')
def save_uploaded_file(uploaded_file):
try:
with open(os.path.join('uploads',uploaded_file.name),'wb') as f:
f.write(uploaded_file.getbuffer())
return 1
except:
return 0
def feature_extraction(img_path,model):
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
expanded_img_array = np.expand_dims(img_array, axis=0)
preprocessed_img = preprocess_input(expanded_img_array)
result = model.predict(preprocessed_img).flatten()
normalized_result = result / norm(result)
return normalized_result
def recommend(features,feature_list):
neighbors = NearestNeighbors(n_neighbors=6, algorithm='brute', metric='euclidean')
neighbors.fit(feature_list)
distances, indices = neighbors.kneighbors([features])
print(distances,indices)
return indices
def recommend_myntra(features,feature_list):
neighbors = NearestNeighbors(n_neighbors=6, algorithm='brute', metric='euclidean')
neighbors.fit(feature_list_myntra)
distances, indices = neighbors.kneighbors([features])
print(distances,indices)
return indices
#
menu = ['FR','FRM','AB']
option = st.sidebar.selectbox("Select your model",menu)
if option=='FR':
uploaded_file = st.file_uploader("Choose an image")
if uploaded_file is not None:
if save_uploaded_file(uploaded_file):
display_image = Image.open(uploaded_file)
st.image(display_image)
# feature extract
features = feature_extraction(os.path.join("uploads",uploaded_file.name),model)
# recommendention
indices = recommend(features,feature_list)
# show
st.header("Recommend For You....")
st.text("")
col1,col2,col3,col4,col5 = st.columns(5)
with col1:
st.image(filenames[indices[0][1]])
with col2:
st.image(filenames[indices[0][2]])
with col3:
st.image(filenames[indices[0][3]])
with col4:
st.image(filenames[indices[0][4]])
with col5:
st.image(filenames[indices[0][5]])
else:
st.header("Some error occured in file upload")
elif option=='FRM':
uploaded_file = st.file_uploader("Choose an image")
if uploaded_file is not None:
if save_uploaded_file(uploaded_file):
display_image = Image.open(uploaded_file)
st.image(display_image)
# feature extract
features = feature_extraction(os.path.join("uploads",uploaded_file.name),model)
# recommendention
indices = recommend_myntra(features,feature_list)
# show
st.header("Recommend For You....")
st.text("")
col1,col2,col3,col4,col5 = st.columns(5)
with col1:
st.image(filenames_myntra[indices[0][1]])
with col2:
st.image(filenames_myntra[indices[0][2]])
with col3:
st.image(filenames_myntra[indices[0][3]])
with col4:
st.image(filenames_myntra[indices[0][4]])
with col5:
st.image(filenames_myntra[indices[0][5]])
else:
st.header("Some error occured in file upload")
elif option=="AB":
st.markdown("FR: First Model Only Recommend Women Fashion Dresses...")
st.markdown("FRM: Second Model Recommend Men Women include also footwears and clothes.")
st.title("Product Recommendation Engine V-2.0")
st.markdown("This Engine Developed by <a href='https://github.com/datamind321'>DataMind Platform</a>",unsafe_allow_html=True)
st.subheader("if you have any query Contact us on : [email protected]")
st.markdown("More on : ")
st.markdown("[![Linkedin](https://content.linkedin.com/content/dam/me/business/en-us/amp/brand-site/v2/bg/LI-Bug.svg.original.svg)](https://www.linkedin.com/in/rahul-rathour-402408231/)",unsafe_allow_html=True)
st.markdown("[![Instagram](https://img.icons8.com/color/1x/instagram-new.png)](https://instagram.com/_technical__mind?igshid=YmMyMTA2M2Y=)")
|