Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -132,23 +132,19 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
|
|
132 |
|
133 |
def find_similar_images(query_embedding, collection, top_k=5, batch_size=500):
|
134 |
query_embedding = query_embedding.reshape(1, -1) # 쿼리 임베딩 차원 조정
|
135 |
-
all_results = []
|
136 |
|
137 |
-
#
|
138 |
-
|
|
|
|
|
|
|
|
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
include=['embeddings', 'metadatas'],
|
146 |
-
start=start,
|
147 |
-
end=end
|
148 |
-
)
|
149 |
-
|
150 |
-
batch_embeddings = np.array(all_data['embeddings'])
|
151 |
-
batch_metadatas = all_data['metadatas']
|
152 |
|
153 |
# 코사인 유사도 계산
|
154 |
similarities = cosine_similarity(query_embedding, batch_embeddings).flatten()
|
@@ -164,7 +160,6 @@ def find_similar_images(query_embedding, collection, top_k=5, batch_size=500):
|
|
164 |
|
165 |
|
166 |
|
167 |
-
|
168 |
# 세션 상태 초기화
|
169 |
if 'step' not in st.session_state:
|
170 |
st.session_state.step = 'input'
|
|
|
132 |
|
133 |
def find_similar_images(query_embedding, collection, top_k=5, batch_size=500):
|
134 |
query_embedding = query_embedding.reshape(1, -1) # 쿼리 임베딩 차원 조정
|
|
|
135 |
|
136 |
+
# 모든 임베딩과 메타데이터를 한 번에 가져옴
|
137 |
+
all_data = collection.get(include=['embeddings', 'metadatas'])
|
138 |
+
all_embeddings = np.array(all_data['embeddings'])
|
139 |
+
all_metadatas = all_data['metadatas']
|
140 |
+
|
141 |
+
all_results = []
|
142 |
|
143 |
+
# 전체 데이터를 batch_size씩 나누어 처리
|
144 |
+
for start in range(0, len(all_embeddings), batch_size):
|
145 |
+
end = start + batch_size
|
146 |
+
batch_embeddings = all_embeddings[start:end]
|
147 |
+
batch_metadatas = all_metadatas[start:end]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
# 코사인 유사도 계산
|
150 |
similarities = cosine_similarity(query_embedding, batch_embeddings).flatten()
|
|
|
160 |
|
161 |
|
162 |
|
|
|
163 |
# 세션 상태 초기화
|
164 |
if 'step' not in st.session_state:
|
165 |
st.session_state.step = 'input'
|