Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,7 @@ def load_image_from_url(url, max_retries=3):
|
|
52 |
else:
|
53 |
return None
|
54 |
|
55 |
-
#
|
56 |
def get_image_embedding(image):
|
57 |
image_tensor = preprocess_val(image).unsqueeze(0).to(device)
|
58 |
with torch.no_grad():
|
@@ -82,7 +82,7 @@ def get_average_embedding(main_image_url, additional_image_urls):
|
|
82 |
|
83 |
if embeddings:
|
84 |
avg_embedding = np.mean(embeddings, axis=0)
|
85 |
-
return avg_embedding.
|
86 |
else:
|
87 |
return None
|
88 |
|
@@ -105,7 +105,7 @@ def update_collection_embeddings():
|
|
105 |
try:
|
106 |
avg_embedding = get_average_embedding(main_image_url, additional_image_urls)
|
107 |
if avg_embedding is not None:
|
108 |
-
batch_embeddings.append(avg_embedding) # μ΄λ―Έ 리μ€νΈ
|
109 |
valid_ids.append(id)
|
110 |
else:
|
111 |
st.warning(f"Failed to generate embedding for item {id}")
|
@@ -122,11 +122,10 @@ def update_collection_embeddings():
|
|
122 |
except Exception as e:
|
123 |
st.error(f"Error updating embeddings: {str(e)}")
|
124 |
st.error(f"First embedding type: {type(batch_embeddings[0])}")
|
125 |
-
st.error(f"First embedding
|
126 |
|
127 |
# μ§ν μν© νμ
|
128 |
st.progress((i + batch_size) / len(all_ids))
|
129 |
-
|
130 |
def find_similar_images(query_embedding, collection, top_k=5):
|
131 |
results = collection.query(
|
132 |
query_embeddings=[query_embedding.squeeze().tolist()],
|
|
|
52 |
else:
|
53 |
return None
|
54 |
|
55 |
+
# get_image_embedding ν¨μ μμ
|
56 |
def get_image_embedding(image):
|
57 |
image_tensor = preprocess_val(image).unsqueeze(0).to(device)
|
58 |
with torch.no_grad():
|
|
|
82 |
|
83 |
if embeddings:
|
84 |
avg_embedding = np.mean(embeddings, axis=0)
|
85 |
+
return avg_embedding.tolist() # numpy λ°°μ΄μ νμ΄μ¬ 리μ€νΈλ‘ λ³ν
|
86 |
else:
|
87 |
return None
|
88 |
|
|
|
105 |
try:
|
106 |
avg_embedding = get_average_embedding(main_image_url, additional_image_urls)
|
107 |
if avg_embedding is not None:
|
108 |
+
batch_embeddings.append(avg_embedding) # μ΄λ―Έ 리μ€νΈ ννμ
|
109 |
valid_ids.append(id)
|
110 |
else:
|
111 |
st.warning(f"Failed to generate embedding for item {id}")
|
|
|
122 |
except Exception as e:
|
123 |
st.error(f"Error updating embeddings: {str(e)}")
|
124 |
st.error(f"First embedding type: {type(batch_embeddings[0])}")
|
125 |
+
st.error(f"First embedding length: {len(batch_embeddings[0])}")
|
126 |
|
127 |
# μ§ν μν© νμ
|
128 |
st.progress((i + batch_size) / len(all_ids))
|
|
|
129 |
def find_similar_images(query_embedding, collection, top_k=5):
|
130 |
results = collection.query(
|
131 |
query_embeddings=[query_embedding.squeeze().tolist()],
|