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': st.markdown("