Ayesha-Majeed commited on
Commit
9d7be5a
·
verified ·
1 Parent(s): 97772dc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -453,16 +453,23 @@ def run_segformer(img_rgb, morph_cleanup=False):
453
  paths_to_try = [
454
  os.path.join(base_dir, "SegFormer_Model", "best_segformer_dice_model"), # Local PC
455
  "best_segformer_dice_model", # Hugging Face Root
456
- os.path.join(os.path.dirname(__file__), "best_segformer_dice_model") # Next to app.py
457
  ]
458
 
 
 
 
 
 
 
459
  model_path = None
460
  for p in paths_to_try:
461
- if os.path.exists(p):
 
462
  model_path = p
463
  break
464
 
465
- # If not found, fallback to Hugging Face standard path just in case
466
  if model_path is None:
467
  model_path = "best_segformer_dice_model"
468
 
 
453
  paths_to_try = [
454
  os.path.join(base_dir, "SegFormer_Model", "best_segformer_dice_model"), # Local PC
455
  "best_segformer_dice_model", # Hugging Face Root
456
+ os.path.join(os.path.dirname(__file__), "best_segformer_dice_model"), # Next to app.py
457
  ]
458
 
459
+ # If files were uploaded directly to the root (no folder)
460
+ if os.path.exists("config.json"):
461
+ paths_to_try.append(".")
462
+ if os.path.exists(os.path.join(os.path.dirname(__file__), "config.json")):
463
+ paths_to_try.append(os.path.dirname(__file__))
464
+
465
  model_path = None
466
  for p in paths_to_try:
467
+ # For SegFormer, the path must contain config.json
468
+ if os.path.exists(p) and os.path.exists(os.path.join(p, "config.json")):
469
  model_path = p
470
  break
471
 
472
+ # Fallback
473
  if model_path is None:
474
  model_path = "best_segformer_dice_model"
475