prthm11 commited on
Commit
4fa11e6
·
verified ·
1 Parent(s): 0931b84

Update app_main.py

Browse files
Files changed (1) hide show
  1. app_main.py +30 -30
app_main.py CHANGED
@@ -305,35 +305,35 @@ def similarity_matching(input_json_path: str) -> str:
305
  # ============================== #
306
  clip_embd = OpenCLIPEmbeddings()
307
 
308
- # ========================================= #
309
- # Walk folders to collect all image paths #
310
- # ========================================= #
311
- folder_image_paths = []
312
- for image_dir in image_dirs:
313
- for root, _, files in os.walk(image_dir):
314
- for fname in files:
315
- if fname.lower().endswith((".png", ".jpg", ".jpeg")):
316
- folder_image_paths.append(os.path.join(root, fname))
317
-
318
- # ============================== #
319
- # EMBED FOLDER IMAGES (REF) #
320
- # ============================== #
321
- img_features = clip_embd.embed_image(folder_image_paths)
322
-
323
- # ============================== #
324
- # Store image embeddings #
325
- # ============================== #
326
- embedding_json = []
327
- for i, path in enumerate(folder_image_paths):
328
- embedding_json.append({
329
- "name":os.path.basename(path),
330
- "file-path": path,
331
- "embeddings": list(img_features[i])
332
- })
333
 
334
- # Save to embeddings.json
335
- with open(f"{OUTPUT_FOLDER}/embeddings.json", "w") as f:
336
- json.dump(embedding_json, f, indent=2)
337
 
338
  # ============================== #
339
  # DECODE SPRITE IMAGES #
@@ -355,8 +355,8 @@ def similarity_matching(input_json_path: str) -> str:
355
  # ============================== #
356
  # COMPUTE SIMILARITIES #
357
  # ============================== #
358
- # with open(f"{OUTPUT_FOLDER}/embeddings.json", "r") as f:
359
- # embedding_json = json.load(f)
360
 
361
  img_matrix = np.array([img["embeddings"] for img in embedding_json])
362
  sprite_matrix = np.array(sprite_features)
 
305
  # ============================== #
306
  clip_embd = OpenCLIPEmbeddings()
307
 
308
+ # # ========================================= #
309
+ # # Walk folders to collect all image paths #
310
+ # # ========================================= #
311
+ # folder_image_paths = []
312
+ # for image_dir in image_dirs:
313
+ # for root, _, files in os.walk(image_dir):
314
+ # for fname in files:
315
+ # if fname.lower().endswith((".png", ".jpg", ".jpeg")):
316
+ # folder_image_paths.append(os.path.join(root, fname))
317
+
318
+ # # ============================== #
319
+ # # EMBED FOLDER IMAGES (REF) #
320
+ # # ============================== #
321
+ # img_features = clip_embd.embed_image(folder_image_paths)
322
+
323
+ # # ============================== #
324
+ # # Store image embeddings #
325
+ # # ============================== #
326
+ # embedding_json = []
327
+ # for i, path in enumerate(folder_image_paths):
328
+ # embedding_json.append({
329
+ # "name":os.path.basename(path),
330
+ # "file-path": path,
331
+ # "embeddings": list(img_features[i])
332
+ # })
333
 
334
+ # # Save to embeddings.json
335
+ # with open(f"{OUTPUT_FOLDER}/embeddings.json", "w") as f:
336
+ # json.dump(embedding_json, f, indent=2)
337
 
338
  # ============================== #
339
  # DECODE SPRITE IMAGES #
 
355
  # ============================== #
356
  # COMPUTE SIMILARITIES #
357
  # ============================== #
358
+ with open(f"{OUTPUT_FOLDER}/embeddings.json", "r") as f:
359
+ embedding_json = json.load(f)
360
 
361
  img_matrix = np.array([img["embeddings"] for img in embedding_json])
362
  sprite_matrix = np.array(sprite_features)