Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,22 +78,22 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
|
|
78 |
|
79 |
return img_with_alpha.convert("RGB"), final_mask, detected_categories
|
80 |
|
81 |
-
# 유클리드 거리 기반으로 유사한 이미지 찾기
|
82 |
def find_similar_images(query_embedding, collection, top_k=5):
|
83 |
-
query_embedding = query_embedding.reshape(1, -1)
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
top_indices = np.argsort(distances)[:top_k]
|
89 |
-
top_metadatas = [collection.get(ids=[str(idx)])['metadatas'][0] for idx in top_indices]
|
90 |
-
top_distances = distances[top_indices]
|
91 |
|
92 |
structured_results = []
|
93 |
for metadata, distance in zip(top_metadatas, top_distances):
|
94 |
structured_results.append({
|
95 |
'info': metadata,
|
96 |
-
'similarity': 1
|
97 |
})
|
98 |
|
99 |
return structured_results
|
|
|
78 |
|
79 |
return img_with_alpha.convert("RGB"), final_mask, detected_categories
|
80 |
|
|
|
81 |
def find_similar_images(query_embedding, collection, top_k=5):
|
82 |
+
query_embedding = query_embedding.reshape(1, -1) # Reshape to 2D array for ChromaDB
|
83 |
+
results = collection.query(
|
84 |
+
query_embeddings=query_embedding,
|
85 |
+
n_results=top_k,
|
86 |
+
include=['metadatas', 'distances']
|
87 |
+
)
|
88 |
|
89 |
+
top_metadatas = results['metadatas'][0]
|
90 |
+
top_distances = results['distances'][0]
|
|
|
|
|
|
|
|
|
91 |
|
92 |
structured_results = []
|
93 |
for metadata, distance in zip(top_metadatas, top_distances):
|
94 |
structured_results.append({
|
95 |
'info': metadata,
|
96 |
+
'similarity': 1 - distance
|
97 |
})
|
98 |
|
99 |
return structured_results
|