sohamnk commited on
Commit
4282b8d
·
verified ·
1 Parent(s): abe843d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -185,9 +185,6 @@ def compare_items():
185
  search_list = payload['searchList']
186
  print(f"\n[COMPARE] Received {len(search_list)} pre-filtered candidates for '{query_item.get('objectName')}'.")
187
 
188
- # --- HIERARCHICAL FILTERING BLOCK HAS BEEN REMOVED ---
189
- # The service now proceeds directly to scoring.
190
-
191
  # --- SCORING ---
192
  results = []
193
  for item in search_list:
@@ -204,18 +201,25 @@ def compare_items():
204
  text_score = total_text_score / len(TEXT_FIELDS_TO_EMBED) if TEXT_FIELDS_TO_EMBED else 0
205
  print(f" - Text Score: {text_score:.4f}")
206
 
207
- # 2. Calculate Image Score
208
  image_score = 0.0
209
  query_img_embs = query_item.get('image_embeddings', [])
210
  item_img_embs = item.get('image_embeddings', [])
211
  if query_img_embs and item_img_embs:
212
  all_img_scores = []
213
- for q_emb in query_img_embs:
214
- for i_emb in item_img_embs:
215
- all_img_scores.append(cosine_similarity(q_emb, i_emb))
 
 
 
 
 
216
  if all_img_scores:
217
  image_score = max(all_img_scores)
218
- print(f" - Image Score: {image_score:.4f}")
 
 
219
 
220
  # 3. Calculate Final Score
221
  final_score = (SCORE_WEIGHTS['text_score'] * text_score + SCORE_WEIGHTS['image_score'] * image_score)
 
185
  search_list = payload['searchList']
186
  print(f"\n[COMPARE] Received {len(search_list)} pre-filtered candidates for '{query_item.get('objectName')}'.")
187
 
 
 
 
188
  # --- SCORING ---
189
  results = []
190
  for item in search_list:
 
201
  text_score = total_text_score / len(TEXT_FIELDS_TO_EMBED) if TEXT_FIELDS_TO_EMBED else 0
202
  print(f" - Text Score: {text_score:.4f}")
203
 
204
+ # 2. Calculate Image Score with detailed logging
205
  image_score = 0.0
206
  query_img_embs = query_item.get('image_embeddings', [])
207
  item_img_embs = item.get('image_embeddings', [])
208
  if query_img_embs and item_img_embs:
209
  all_img_scores = []
210
+ print(f" - Image Pair Scores:") # Header for detailed scores
211
+ for i, q_emb in enumerate(query_img_embs):
212
+ for j, i_emb in enumerate(item_img_embs):
213
+ # Calculate the score for this specific pair
214
+ pair_score = cosine_similarity(q_emb, i_emb)
215
+ # Print the score for this pair
216
+ print(f" - Query Img {i+1} vs Item Img {j+1}: {pair_score:.4f}")
217
+ all_img_scores.append(pair_score)
218
  if all_img_scores:
219
  image_score = max(all_img_scores)
220
+
221
+ # Use a clearer label for the max score
222
+ print(f" - Max Image Score: {image_score:.4f}")
223
 
224
  # 3. Calculate Final Score
225
  final_score = (SCORE_WEIGHTS['text_score'] * text_score + SCORE_WEIGHTS['image_score'] * image_score)