timo1227 commited on
Commit
5cd92f1
·
1 Parent(s): 39c3c6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -30
app.py CHANGED
@@ -6,7 +6,7 @@ import os
6
  import streamlit as st
7
 
8
 
9
- # @st.cache_resource()
10
  def load_model():
11
  print("Loading model...")
12
  # Load the pre-trained ResNet-50 model and set it to eval mode
@@ -56,7 +56,7 @@ def load_model():
56
  return features_dict
57
 
58
 
59
- # @st.cache_resource()
60
  def create_nearest_neighbors_object(features_dict):
61
  print("Creating nearest neighbors object...")
62
  import numpy as np
@@ -99,10 +99,6 @@ def get_nearest_neighbors(image_path):
99
  use_column_width=True,
100
  )
101
 
102
-
103
- # call the function with George W. Bush's image
104
- # get_nearest_neighbors('lfw/George_W_Bush/George_W_Bush_0001.jpg')
105
-
106
  # SteamLit App
107
 
108
  allow_output_mutation = True
@@ -115,30 +111,6 @@ st.title("Similarity Search")
115
  # Subtitle
116
  st.write("This app finds the 10 most similar images to a query image.")
117
 
118
- # Upload the query image Or Select the query image from ./lfw folder start with None
119
- # upload_query = st.file_uploader("Upload an image", type=["jpg", "png"])
120
- # if upload_query is not None:
121
- # # Display the query image
122
- # st.image(upload_query, caption="Query Image", use_column_width=True)
123
- # # Temp save the query image to ./query_image/query_image.jpg
124
- # try:
125
- # os.mkdir("query_image")
126
- # except:
127
- # pass
128
- # with open("query_image/query_image.jpg", "wb") as f:
129
- # f.write(upload_query.getbuffer())
130
-
131
- # # save path to query_image
132
- # upload_query = "query_image/query_image.jpg"
133
-
134
- # # Find the 10 most similar images
135
- # if st.button("Find Similar Images"):
136
- # # Call the get nearest neighbors function
137
- # nearest10 = get_nearest_neighbors(upload_query)
138
- # Delete the query image
139
- # os.remove(upload_query)
140
-
141
-
142
  query_image = st.selectbox("Or select an image from the list", os.listdir("lfw"))
143
  # Display the query image from dir ./lfw/query_image/query_image_0001.jpg
144
  print("lfw/" + query_image + "/" + query_image + "_0001.jpg")
 
6
  import streamlit as st
7
 
8
 
9
+ @st.cache()
10
  def load_model():
11
  print("Loading model...")
12
  # Load the pre-trained ResNet-50 model and set it to eval mode
 
56
  return features_dict
57
 
58
 
59
+ @st.cache()
60
  def create_nearest_neighbors_object(features_dict):
61
  print("Creating nearest neighbors object...")
62
  import numpy as np
 
99
  use_column_width=True,
100
  )
101
 
 
 
 
 
102
  # SteamLit App
103
 
104
  allow_output_mutation = True
 
111
  # Subtitle
112
  st.write("This app finds the 10 most similar images to a query image.")
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  query_image = st.selectbox("Or select an image from the list", os.listdir("lfw"))
115
  # Display the query image from dir ./lfw/query_image/query_image_0001.jpg
116
  print("lfw/" + query_image + "/" + query_image + "_0001.jpg")