Spaces:
Sleeping
Sleeping
devjas1
commited on
Commit
·
5054409
1
Parent(s):
346c859
(FIX)[Remove Legacy Model Loader]:
Browse files- Deleted outdated legacy fallback for model loading via `MODEL_CONFIG`.
- Unified error handling for unknown models; now lists available choices using `choices()`.`
- Ensures function always returns None, False for unknown models.
- core_logic.py +4 -32
core_logic.py
CHANGED
@@ -62,7 +62,7 @@ def load_model(model_name):
|
|
62 |
model.eval()
|
63 |
weights_loaded = True
|
64 |
|
65 |
-
except
|
66 |
continue
|
67 |
|
68 |
if not weights_loaded:
|
@@ -75,37 +75,9 @@ def load_model(model_name):
|
|
75 |
|
76 |
return model, weights_loaded
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
model_class = config["class"]
|
82 |
-
model_path = config["path"]
|
83 |
-
|
84 |
-
# Initialize model
|
85 |
-
model = model_class(input_length=TARGET_LEN)
|
86 |
-
|
87 |
-
# Check if model file exists
|
88 |
-
if not os.path.exists(model_path):
|
89 |
-
st.warning(f"⚠️ Model weights not found: {model_path}")
|
90 |
-
st.info("Using randomly initialized model for demonstration purposes.")
|
91 |
-
return model, False
|
92 |
-
|
93 |
-
# Get mtime for cache invalidation
|
94 |
-
mtime = os.path.getmtime(model_path)
|
95 |
-
|
96 |
-
# Load weights
|
97 |
-
state_dict = load_state_dict(mtime, model_path)
|
98 |
-
if state_dict:
|
99 |
-
model.load_state_dict(state_dict, strict=True)
|
100 |
-
model.eval()
|
101 |
-
return model, True
|
102 |
-
else:
|
103 |
-
return model, False
|
104 |
-
else:
|
105 |
-
st.error(
|
106 |
-
f"❌ Unknown model '{model_name}'. Available models: {list(MODEL_CONFIG.keys())}"
|
107 |
-
)
|
108 |
-
return None, False
|
109 |
|
110 |
|
111 |
def cleanup_memory():
|
|
|
62 |
model.eval()
|
63 |
weights_loaded = True
|
64 |
|
65 |
+
except (OSError, RuntimeError):
|
66 |
continue
|
67 |
|
68 |
if not weights_loaded:
|
|
|
75 |
|
76 |
return model, weights_loaded
|
77 |
|
78 |
+
# If model not in registry, raise error
|
79 |
+
st.error(f"Unknown model '{model_name}'. Available models: {choices()}")
|
80 |
+
return None, False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
|
83 |
def cleanup_memory():
|