sailer99 commited on
Commit
3d006b5
1 Parent(s): 2ac1d0a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +62 -0
  2. requirments.txt +6 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pickle as pkl
3
+ import tensorflow as tf
4
+ from tensorflow.keras.applications.resnet50 import ResNet50,preprocess_input
5
+ from tensorflow.keras.preprocessing import image
6
+ from tensorflow.keras.layers import GlobalMaxPool2D
7
+
8
+ from sklearn.neighbors import NearestNeighbors
9
+ import os
10
+ from numpy.linalg import norm
11
+ import streamlit as st
12
+
13
+ st.header('🧚‍♀️ Moda Tavsiye Sistemi 🧚‍♀️')
14
+
15
+ Image_features = pkl.load(open('Images_features.pkl','rb'))
16
+ filenames = pkl.load(open('filenames.pkl','rb'))
17
+
18
+ def extract_features_from_images(image_path, model):
19
+ img = image.load_img(image_path, target_size=(224,224))
20
+ img_array = image.img_to_array(img)
21
+ img_expand_dim = np.expand_dims(img_array, axis=0)
22
+ img_preprocess = preprocess_input(img_expand_dim)
23
+ result = model.predict(img_preprocess).flatten()
24
+ norm_result = result/norm(result)
25
+ return norm_result
26
+
27
+
28
+ model = ResNet50(weights='imagenet', include_top=False, input_shape=(224,224,3))
29
+ model.trainable = False
30
+
31
+ model = tf.keras.models.Sequential([
32
+ model,
33
+ GlobalMaxPool2D()
34
+ ])
35
+ model.build((None, 224, 224, 3))
36
+
37
+ neighbors = NearestNeighbors(n_neighbors=6, algorithm='brute', metric='euclidean')
38
+ neighbors.fit(Image_features)
39
+
40
+ uploaded_file = st.file_uploader("Resim yükle", type=["jpg","png"])
41
+
42
+ if uploaded_file is not None:
43
+ with open(os.path.join('upload', uploaded_file.name), 'wb') as f:
44
+ f.write(uploaded_file.getbuffer())
45
+ st.subheader('Yüklenen Resim')
46
+ st.image(uploaded_file)
47
+ input_img_features = extract_features_from_images(uploaded_file, model)
48
+ distance,indices = neighbors.kneighbors([input_img_features])
49
+
50
+ st.subheader('Tavsiye Edilen Resimler')
51
+ col1,col2,col3,col4,col5 = st.columns(5)
52
+ with col1:
53
+ st.image(filenames[indices[0][1]])
54
+ with col2:
55
+ st.image(filenames[indices[0][2]])
56
+ with col3:
57
+ st.image(filenames[indices[0][3]])
58
+ with col4:
59
+ st.image(filenames[indices[0][4]])
60
+ with col5:
61
+ st.image(filenames[indices[0][5]])
62
+
requirments.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ pickle
3
+ tensorflow
4
+ scikit-learn
5
+ numpy
6
+ os