Update app.py
Browse files
app.py
CHANGED
|
@@ -127,7 +127,7 @@ classifier = SpeakerClassifier(input_dim=768, hidden_dim=512, num_classes=num_cl
|
|
| 127 |
|
| 128 |
loaded = False
|
| 129 |
if isinstance(ckpt, dict):
|
| 130 |
-
for key in ['classifier_state', 'classifier_state_dict', 'model_state_dict', 'state_dict', 'model']:
|
| 131 |
if key in ckpt:
|
| 132 |
try:
|
| 133 |
classifier.load_state_dict(ckpt[key])
|
|
@@ -151,7 +151,14 @@ if isinstance(ckpt, dict):
|
|
| 151 |
loaded = True
|
| 152 |
except Exception as e2:
|
| 153 |
print(f"Direct load failed: {e2}")
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
if 'base_model_state' in ckpt:
|
| 156 |
try:
|
| 157 |
base_model.load_state_dict(ckpt['base_model_state'], strict=False)
|
|
@@ -515,7 +522,7 @@ def reset_lockout(user_id):
|
|
| 515 |
|
| 516 |
|
| 517 |
# CREATE FASTAPI APP FIRST (before Gradio)
|
| 518 |
-
|
| 519 |
|
| 520 |
app.add_middleware(
|
| 521 |
CORSMiddleware,
|
|
@@ -924,7 +931,7 @@ async def session_liveness_b64(request: Request):
|
|
| 924 |
return JSONResponse(status_code=500, content={"success": False, "message": str(e)})
|
| 925 |
|
| 926 |
# Mount Gradio ON the FastAPI app (not the other way around)
|
| 927 |
-
app =
|
| 928 |
app.add_middleware(
|
| 929 |
CORSMiddleware,
|
| 930 |
allow_origins=["*"],
|
|
|
|
| 127 |
|
| 128 |
loaded = False
|
| 129 |
if isinstance(ckpt, dict):
|
| 130 |
+
for key in ['classifier_state', 'classifier_state_dict', 'model_state_dict', 'state_dict', 'model', 'embedding_head_state']:
|
| 131 |
if key in ckpt:
|
| 132 |
try:
|
| 133 |
classifier.load_state_dict(ckpt[key])
|
|
|
|
| 151 |
loaded = True
|
| 152 |
except Exception as e2:
|
| 153 |
print(f"Direct load failed: {e2}")
|
| 154 |
+
if not loaded and 'embedding_head_state' in ckpt and 'aam_softmax_state' in ckpt:
|
| 155 |
+
try:
|
| 156 |
+
classifier.fc1.load_state_dict(ckpt['embedding_head_state'])
|
| 157 |
+
classifier.aam.load_state_dict(ckpt['aam_softmax_state'])
|
| 158 |
+
print("Loaded classifier from embedding_head_state + aam_softmax_state")
|
| 159 |
+
loaded = True
|
| 160 |
+
except Exception as e:
|
| 161 |
+
print(f"Split load failed: {e}")
|
| 162 |
if 'base_model_state' in ckpt:
|
| 163 |
try:
|
| 164 |
base_model.load_state_dict(ckpt['base_model_state'], strict=False)
|
|
|
|
| 522 |
|
| 523 |
|
| 524 |
# CREATE FASTAPI APP FIRST (before Gradio)
|
| 525 |
+
app = FastAPI(title="ATM Voice Authentication API", version="1.0.0")
|
| 526 |
|
| 527 |
app.add_middleware(
|
| 528 |
CORSMiddleware,
|
|
|
|
| 931 |
return JSONResponse(status_code=500, content={"success": False, "message": str(e)})
|
| 932 |
|
| 933 |
# Mount Gradio ON the FastAPI app (not the other way around)
|
| 934 |
+
app = FastAPI(title="ATM Voice Authentication API", version="1.0.0")
|
| 935 |
app.add_middleware(
|
| 936 |
CORSMiddleware,
|
| 937 |
allow_origins=["*"],
|