prthm11 commited on
Commit
6564ed2
·
verified ·
1 Parent(s): 713df1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -594,6 +594,17 @@ def choose_top_candidates(embedding_results, phash_results, imgmatch_results, to
594
  print("\nConsensus (in top-{0} of ALL metrics): {1}".format(top_k, result["consensus_topk"]))
595
 
596
  return result
 
 
 
 
 
 
 
 
 
 
 
597
 
598
  # Helper function to load the block catalog from a JSON file
599
  def _load_block_catalog(block_type: str) -> Dict:
@@ -2235,7 +2246,8 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
2235
  matched_filename = os.path.basename(matched_image_path)
2236
 
2237
  # If it's a sprite (under SPRITE_DIR) -> copy sprite assets and read sprite.json
2238
- if matched_folder.startswith(sprite_base_path) and matched_folder not in copied_sprite_folders:
 
2239
  copied_sprite_folders.add(matched_folder)
2240
  sprite_json_path = os.path.join(matched_folder, "sprite.json")
2241
  if os.path.exists(sprite_json_path):
@@ -2260,7 +2272,8 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
2260
  print("Failed to copy sprite asset %s: %s", src, e)
2261
 
2262
  # If it's a backdrop (under BACKDROP_DIR) -> copy backdrop assets and read project.json for stage
2263
- if matched_folder.startswith(backdrop_base_path) and matched_folder not in copied_backdrop_folders:
 
2264
  copied_backdrop_folders.add(matched_folder)
2265
  # copy matched backdrop image
2266
  try:
 
594
  print("\nConsensus (in top-{0} of ALL metrics): {1}".format(top_k, result["consensus_topk"]))
595
 
596
  return result
597
+
598
+ def is_subpath(path: str, base: str) -> bool:
599
+ """Return True if path is inside base (works across OSes)."""
600
+ try:
601
+ p = os.path.normpath(os.path.abspath(path))
602
+ b = os.path.normpath(os.path.abspath(base))
603
+ if os.name == "nt":
604
+ p = p.lower(); b = b.lower()
605
+ return os.path.commonpath([p, b]) == b
606
+ except Exception:
607
+ return False
608
 
609
  # Helper function to load the block catalog from a JSON file
610
  def _load_block_catalog(block_type: str) -> Dict:
 
2246
  matched_filename = os.path.basename(matched_image_path)
2247
 
2248
  # If it's a sprite (under SPRITE_DIR) -> copy sprite assets and read sprite.json
2249
+ # if matched_folder.startswith(sprite_base_path) and matched_folder not in copied_sprite_folders:
2250
+ if is_subpath(matched_folder, sprite_base_path) and matched_folder not in copied_sprite_folders:
2251
  copied_sprite_folders.add(matched_folder)
2252
  sprite_json_path = os.path.join(matched_folder, "sprite.json")
2253
  if os.path.exists(sprite_json_path):
 
2272
  print("Failed to copy sprite asset %s: %s", src, e)
2273
 
2274
  # If it's a backdrop (under BACKDROP_DIR) -> copy backdrop assets and read project.json for stage
2275
+ # if matched_folder.startswith(backdrop_base_path) and matched_folder not in copied_backdrop_folders:
2276
+ if is_subpath(matched_folder, backdrop_base_path) and matched_folder not in copied_backdrop_folders:
2277
  copied_backdrop_folders.add(matched_folder)
2278
  # copy matched backdrop image
2279
  try: