Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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'
|