leedoming commited on
Commit
a0e438d
β€’
1 Parent(s): 9153745

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -52,7 +52,7 @@ def load_image_from_url(url, max_retries=3):
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,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.squeeze().tolist() # numpy 배열을 파이썬 리슀트둜 λ³€ν™˜
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 shape: {len(batch_embeddings[0])}")
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()],