Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -89,14 +89,10 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
|
|
89 |
def find_similar_images(query_embedding, collection, top_k=5):
|
90 |
# ๋ชจ๋ ์๋ฒ ๋ฉ์ ๊ฐ์ ธ์ด
|
91 |
all_embeddings = collection.get(include=['embeddings'])['embeddings']
|
92 |
-
if len(all_embeddings) == 0:
|
93 |
-
st.error("No embeddings found in the collection.")
|
94 |
-
return []
|
95 |
-
|
96 |
database_embeddings = np.array(all_embeddings)
|
97 |
|
98 |
# ์ ์ฌ๋ ๊ณ์ฐ
|
99 |
-
similarities =
|
100 |
top_indices = np.argsort(similarities)[::-1][:top_k]
|
101 |
|
102 |
# ๋ฉํ๋ฐ์ดํฐ ๊ฐ์ ธ์ด
|
@@ -108,23 +104,13 @@ def find_similar_images(query_embedding, collection, top_k=5):
|
|
108 |
# ๋ฒกํฐ ID๋ฅผ ํจ๊ป ๊ฐ์ ธ์์ ํ์ธ
|
109 |
vector_data = collection.get(include=['embeddings', 'metadatas', 'ids'])
|
110 |
|
111 |
-
for idx, vector_id in enumerate(vector_data['ids']):
|
112 |
-
st.write(f"ID: {vector_id}, Embedding: {vector_data['embeddings'][idx]}")
|
113 |
-
if len(all_data) == 0:
|
114 |
-
st.error("No metadatas found in the collection.")
|
115 |
-
return []
|
116 |
-
|
117 |
top_metadatas = [all_data[idx] for idx in top_indices]
|
118 |
|
119 |
results = []
|
120 |
for idx, metadata in enumerate(top_metadatas):
|
121 |
-
image_urls = metadata['image_url'].split(',')
|
122 |
-
representative_image_url = image_urls[0] if image_urls else None
|
123 |
-
|
124 |
results.append({
|
125 |
'info': metadata,
|
126 |
-
'similarity': similarities[top_indices[idx]]
|
127 |
-
'image_url': representative_image_url
|
128 |
})
|
129 |
return results
|
130 |
|
|
|
89 |
def find_similar_images(query_embedding, collection, top_k=5):
|
90 |
# ๋ชจ๋ ์๋ฒ ๋ฉ์ ๊ฐ์ ธ์ด
|
91 |
all_embeddings = collection.get(include=['embeddings'])['embeddings']
|
|
|
|
|
|
|
|
|
92 |
database_embeddings = np.array(all_embeddings)
|
93 |
|
94 |
# ์ ์ฌ๋ ๊ณ์ฐ
|
95 |
+
similarities = np.dot(database_embeddings, query_embedding.T).squeeze()
|
96 |
top_indices = np.argsort(similarities)[::-1][:top_k]
|
97 |
|
98 |
# ๋ฉํ๋ฐ์ดํฐ ๊ฐ์ ธ์ด
|
|
|
104 |
# ๋ฒกํฐ ID๋ฅผ ํจ๊ป ๊ฐ์ ธ์์ ํ์ธ
|
105 |
vector_data = collection.get(include=['embeddings', 'metadatas', 'ids'])
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
top_metadatas = [all_data[idx] for idx in top_indices]
|
108 |
|
109 |
results = []
|
110 |
for idx, metadata in enumerate(top_metadatas):
|
|
|
|
|
|
|
111 |
results.append({
|
112 |
'info': metadata,
|
113 |
+
'similarity': similarities[top_indices[idx]]
|
|
|
114 |
})
|
115 |
return results
|
116 |
|