JoJosmin commited on
Commit
e4aea0c
โ€ข
1 Parent(s): a81aa5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -29
app.py CHANGED
@@ -87,51 +87,25 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
87
  return img_with_alpha.convert("RGB"), final_mask, detected_categories # Return detected categories
88
 
89
 
90
- #def find_similar_images(query_embedding, collection, top_k=5):
91
- # all_embeddings = collection.get(include=['embeddings'])['embeddings']
92
- # database_embeddings = np.array(all_embeddings)
93
- # similarities = np.dot(database_embeddings, query_embedding.T).squeeze()
94
- # top_indices = np.argsort(similarities)[::-1][:top_k]
95
- #
96
- # all_data = collection.get(include=['metadatas'])['metadatas']
97
- # top_metadatas = [all_data[idx] for idx in top_indices]
98
-
99
- # results = []
100
- # for idx, metadata in enumerate(top_metadatas):
101
- # results.append({
102
- # 'info': metadata,
103
- # 'similarity': similarities[top_indices[idx]]
104
- # })
105
- # return results
106
-
107
  def find_similar_images(query_embedding, collection, top_k=5):
108
- # ๋ชจ๋“  ์ž„๋ฒ ๋”ฉ์„ ๊ฐ€์ ธ์˜ด
109
  all_embeddings = collection.get(include=['embeddings'])['embeddings']
110
  database_embeddings = np.array(all_embeddings)
111
-
112
- # ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ
113
- similarities = cosine_similarity(database_embeddings, query_embedding.reshape(1, -1)).squeeze()
114
  top_indices = np.argsort(similarities)[::-1][:top_k]
115
 
116
- # ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ด
117
  all_data = collection.get(include=['metadatas'])['metadatas']
118
  top_metadatas = [all_data[idx] for idx in top_indices]
119
 
120
  results = []
121
  for idx, metadata in enumerate(top_metadatas):
122
- # ์ด๋ฏธ์ง€ URLs ํ•„๋“œ๊ฐ€ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด๋กœ ์ €์žฅ๋œ ๊ฒฝ์šฐ, ์ด๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜
123
- image_urls = metadata['image_url'].split(',')
124
- # ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€๋ฅผ ๋Œ€ํ‘œ ์ด๋ฏธ์ง€๋กœ ์‚ฌ์šฉ
125
- representative_image_url = image_urls[0] if image_urls else None
126
-
127
  results.append({
128
  'info': metadata,
129
- 'similarity': similarities[top_indices[idx]],
130
- 'image_url': representative_image_url # ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€ URL ์‚ฌ์šฉ
131
  })
132
  return results
133
 
134
 
 
135
  # ์„ธ์…˜ ์ƒํƒœ ์ดˆ๊ธฐํ™”
136
  if 'step' not in st.session_state:
137
  st.session_state.step = 'input'
 
87
  return img_with_alpha.convert("RGB"), final_mask, detected_categories # Return detected categories
88
 
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  def find_similar_images(query_embedding, collection, top_k=5):
 
91
  all_embeddings = collection.get(include=['embeddings'])['embeddings']
92
  database_embeddings = np.array(all_embeddings)
93
+ similarities = np.dot(database_embeddings, query_embedding.T).squeeze()
 
 
94
  top_indices = np.argsort(similarities)[::-1][:top_k]
95
 
 
96
  all_data = collection.get(include=['metadatas'])['metadatas']
97
  top_metadatas = [all_data[idx] for idx in top_indices]
98
 
99
  results = []
100
  for idx, metadata in enumerate(top_metadatas):
 
 
 
 
 
101
  results.append({
102
  'info': metadata,
103
+ 'similarity': similarities[top_indices[idx]]
 
104
  })
105
  return results
106
 
107
 
108
+
109
  # ์„ธ์…˜ ์ƒํƒœ ์ดˆ๊ธฐํ™”
110
  if 'step' not in st.session_state:
111
  st.session_state.step = 'input'