Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -131,25 +131,21 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
|
|
131 |
# return structured_results
|
132 |
|
133 |
def find_similar_images(query_embedding, collection, top_k=5):
|
134 |
-
#
|
135 |
-
all_data = collection.get(include=['embeddings', 'metadatas'])
|
136 |
-
all_embeddings = np.array([
|
137 |
-
all_metadatas = all_data['metadatas']
|
138 |
-
|
139 |
-
# ์ฟผ๋ฆฌ
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
'info': all_metadatas[idx],
|
150 |
-
'similarity': similarities[idx]
|
151 |
-
})
|
152 |
-
|
153 |
return results
|
154 |
|
155 |
|
|
|
131 |
# return structured_results
|
132 |
|
133 |
def find_similar_images(query_embedding, collection, top_k=5):
|
134 |
+
# ๋ชจ๋ ์๋ฒ ๋ฉ๊ณผ ๋ฉํ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
135 |
+
all_data = collection.get(include=['embeddings', 'metadatas'])
|
136 |
+
all_embeddings = np.array(all_data['embeddings']) # ์๋ฒ ๋ฉ ๋ฐฐ์ด๋ก ๋ณํ
|
137 |
+
all_metadatas = all_data['metadatas'] # ๋ฉํ๋ฐ์ดํฐ ๋ฆฌ์คํธ
|
138 |
+
|
139 |
+
# ์ฟผ๋ฆฌ ์๋ฒ ๋ฉ๊ณผ์ ์ฝ์ฌ์ธ ์ ์ฌ๋ ๊ณ์ฐ
|
140 |
+
query_embedding = query_embedding.reshape(1, -1) # ์ฟผ๋ฆฌ ์๋ฒ ๋ฉ ์ฐจ์ ์กฐ์
|
141 |
+
similarities = cosine_similarity(query_embedding, all_embeddings).flatten() # ์ ์ฌ๋ ๊ณ์ฐ
|
142 |
+
|
143 |
+
# ์ ์ฌ๋์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ์์ผ๋ก ๋ฌถ๊ณ , ์ ์ฌ๋๊ฐ ๋์ ์์๋๋ก ์ ๋ ฌ
|
144 |
+
similarity_metadata_pairs = list(zip(similarities, all_metadatas))
|
145 |
+
sorted_pairs = sorted(similarity_metadata_pairs, key=lambda x: x[0], reverse=True)[:top_k]
|
146 |
+
|
147 |
+
# ์ต์ข
๊ฒฐ๊ณผ ํ์์ผ๋ก ๋ฐํ
|
148 |
+
results = [{'info': metadata, 'similarity': similarity} for similarity, metadata in sorted_pairs]
|
|
|
|
|
|
|
|
|
149 |
return results
|
150 |
|
151 |
|