Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
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")
|
| 457 |
]
|
| 458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
model_path = None
|
| 460 |
for p in paths_to_try:
|
| 461 |
-
|
|
|
|
| 462 |
model_path = p
|
| 463 |
break
|
| 464 |
|
| 465 |
-
#
|
| 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 |
|