Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -110,53 +110,27 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
|
|
110 |
|
111 |
# return structured_results
|
112 |
|
113 |
-
#def find_similar_images(query_embedding, collection, top_k=5):
|
114 |
-
# query_embedding = query_embedding.reshape(1, -1) # Reshape to 2D array for ChromaDB
|
115 |
-
# results = collection.query(
|
116 |
-
# query_embeddings=query_embedding,
|
117 |
-
# n_results=top_k,
|
118 |
-
# include=['metadatas', 'distances']
|
119 |
-
# )
|
120 |
-
#
|
121 |
-
# top_metadatas = results['metadatas'][0]
|
122 |
-
# top_distances = results['distances'][0]
|
123 |
-
#
|
124 |
-
# structured_results = []
|
125 |
-
# for metadata, distance in zip(top_metadatas, top_distances):
|
126 |
-
# structured_results.append({
|
127 |
-
# 'info': metadata,
|
128 |
-
# 'similarity': 1 - distance
|
129 |
-
# })
|
130 |
-
#
|
131 |
-
# return structured_results
|
132 |
-
|
133 |
-
def get_all_embeddings_from_collection(collection):
|
134 |
-
all_data = collection.get(include=['embeddings']) # 모든 데이터 가져오기
|
135 |
-
all_embeddings = np.array([data['embedding'] for data in all_data['embeddings']]) # 임베딩 추출
|
136 |
-
return all_embeddings
|
137 |
-
|
138 |
def find_similar_images(query_embedding, collection, top_k=5):
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
# 결과 정리
|
152 |
-
results = []
|
153 |
-
for idx, metadata in enumerate(top_metadatas):
|
154 |
-
results.append({
|
155 |
'info': metadata,
|
156 |
-
'similarity':
|
157 |
})
|
158 |
|
159 |
-
return
|
|
|
|
|
160 |
|
161 |
# 세션 상태 초기화
|
162 |
if 'step' not in st.session_state:
|
|
|
110 |
|
111 |
# return structured_results
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
def find_similar_images(query_embedding, collection, top_k=5):
|
114 |
+
query_embedding = query_embedding.reshape(1, -1) # Reshape to 2D array for ChromaDB
|
115 |
+
results = collection.query(
|
116 |
+
query_embeddings=query_embedding,
|
117 |
+
n_results=top_k,
|
118 |
+
include=['metadatas', 'distances']
|
119 |
+
)
|
120 |
|
121 |
+
top_metadatas = results['metadatas'][0]
|
122 |
+
top_distances = results['distances'][0]
|
123 |
+
|
124 |
+
structured_results = []
|
125 |
+
for metadata, distance in zip(top_metadatas, top_distances):
|
126 |
+
structured_results.append({
|
|
|
|
|
|
|
|
|
|
|
127 |
'info': metadata,
|
128 |
+
'similarity': 1 - distance
|
129 |
})
|
130 |
|
131 |
+
return structured_results
|
132 |
+
|
133 |
+
|
134 |
|
135 |
# 세션 상태 초기화
|
136 |
if 'step' not in st.session_state:
|