Bitha commited on
Commit
5255a02
1 Parent(s): 0026f93

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +104 -0
  2. fashion.csv +0 -0
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ import numpy as np
5
+ import pandas as pd
6
+ from PIL import Image
7
+ from PIL import ImageFile
8
+ import urllib.request
9
+ #from IPython.display import display, Image
10
+ from sklearn.metrics import pairwise_distances
11
+ from datetime import datetime
12
+ import streamlit as st
13
+
14
+
15
+ st.set_option('deprecation.showfileUploaderEncoding', False)
16
+
17
+ fashion_df = pd.read_csv("./fashion.csv")
18
+ boys_extracted_features = np.load('./Boys_ResNet_features.npy')
19
+ boys_Productids = np.load('./Boys_ResNet_feature_product_ids.npy')
20
+ girls_extracted_features = np.load('./Girls_ResNet_features.npy')
21
+ girls_Productids = np.load('./Girls_ResNet_feature_product_ids.npy')
22
+ men_extracted_features = np.load('./Men_ResNet_features.npy')
23
+ men_Productids = np.load('./Men_ResNet_feature_product_ids.npy')
24
+ women_extracted_features = np.load('./Women_ResNet_features.npy')
25
+ women_Productids = np.load('./Women_ResNet_feature_product_ids.npy')
26
+ fashion_df["ProductId"] = fashion_df["ProductId"].astype(str)
27
+
28
+ st.image("https://storage.googleapis.com/danacita-website-v3-prd/website_v3/images/biaya_bootcamp__kursus_hacktiv8_6.original.png")
29
+ st.markdown('---')
30
+ st.subheader('FashClass - HCK-14 Final Project')
31
+ st.write('Name :')
32
+ st.write('1. Anjas Fajar Maulana (Data Science)')
33
+ st.write('2. Fazrin Muhammad (Data Analyst)')
34
+ st.write('3. Naufal Andika Ramadhan (Data Engineer)')
35
+ st.write('4. Salsa Sabitha Hurriyah (Data Science)')
36
+
37
+ st.write('---')
38
+ def load_data(file_path):
39
+ return pd.read_csv(file_path)
40
+
41
+ # Path to the CSV file
42
+ file_path = "/Users/salsasabithah/Documents/FTDS/Final_Project/cadangan_deployment/fashion.csv"
43
+
44
+ # Load the data
45
+ data = load_data(file_path)
46
+
47
+ # Display the data using Streamlit
48
+ st.write("### List of Product")
49
+ st.write(data)
50
+
51
+ st.write('---')
52
+ def get_similar_products_cnn(product_id, num_results):
53
+ if(fashion_df[fashion_df['ProductId']==product_id]['Gender'].values[0]=="Boys"):
54
+ extracted_features = boys_extracted_features
55
+ Productids = boys_Productids
56
+ elif(fashion_df[fashion_df['ProductId']==product_id]['Gender'].values[0]=="Girls"):
57
+ extracted_features = girls_extracted_features
58
+ Productids = girls_Productids
59
+ elif(fashion_df[fashion_df['ProductId']==product_id]['Gender'].values[0]=="Men"):
60
+ extracted_features = men_extracted_features
61
+ Productids = men_Productids
62
+ elif(fashion_df[fashion_df['ProductId']==product_id]['Gender'].values[0]=="Women"):
63
+ extracted_features = women_extracted_features
64
+ Productids = women_Productids
65
+ Productids = list(Productids)
66
+ doc_id = Productids.index(product_id)
67
+ pairwise_dist = pairwise_distances(extracted_features, extracted_features[doc_id].reshape(1,-1))
68
+ indices = np.argsort(pairwise_dist.flatten())[0:num_results]
69
+ pdists = np.sort(pairwise_dist.flatten())[0:num_results]
70
+ st.write("""
71
+ #### input item details
72
+ """)
73
+ ip_row = fashion_df[['ImageURL','ProductTitle']].loc[fashion_df['ProductId']==Productids[indices[0]]]
74
+ for indx, row in ip_row.iterrows():
75
+ image = Image.open(urllib.request.urlopen(row['ImageURL']))
76
+ image = image.resize((224,224))
77
+ st.image(image)
78
+ st.write(f"Product Title: {row['ProductTitle']}")
79
+ st.write(f"""
80
+ #### Top {num_results-1} Recommended items
81
+ """)
82
+ for i in range(1,len(indices)):
83
+ rows = fashion_df[['ImageURL','ProductTitle']].loc[fashion_df['ProductId']==Productids[indices[i]]]
84
+ for indx, row in rows.iterrows():
85
+ #image = Image.open(Image(url=row['ImageURL'], width = 224, height = 224,embed=True))
86
+ image = Image.open(urllib.request.urlopen(row['ImageURL']))
87
+ image = image.resize((224,224))
88
+ st.image(image)
89
+ st.write(f"Product Title: {row['ProductTitle']}")
90
+ st.write(f"Euclidean Distance from input image: {pdists[i]}")
91
+
92
+ st.write("""
93
+ ## FashClass Recommendation
94
+ """
95
+ )
96
+
97
+
98
+ user_input1 = st.text_input("Enter the item id")
99
+ user_input2 = st.text_input("Enter number of products to be recommended")
100
+
101
+
102
+ button = st.button('Generate recommendations')
103
+ if button:
104
+ get_similar_products_cnn(str(user_input1), int(user_input2))
fashion.csv ADDED
The diff for this file is too large to render. See raw diff