cuhgrel commited on
Commit
b404ee5
·
1 Parent(s): 3edbe03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -26,16 +26,23 @@ def load_models():
26
  models['hifigan'] = HifiGanModel.restore_from("models/hifigan_en.nemo").to(device)
27
  models['hifigan'].eval()
28
 
29
- # Load the Spectrogram Generators
30
  models['en'] = FastPitchModel.restore_from("models/fastpitch_en.nemo").to(device)
31
  models['en'].eval()
32
 
33
- models['bikol'] = FastPitchModel.restore_from("models/fastpitch_bikol_repacked.nemo").to(device)
 
 
 
 
 
34
  models['bikol'].eval()
35
 
36
  print("All models loaded successfully.")
37
  except Exception as e:
38
  print(f"FATAL: Could not load models. Error: {e}")
 
 
39
  # In a real app, you might want the app to fail fast if models can't load.
40
 
41
  # --- 3. Define API Request and Response Models ---
@@ -89,9 +96,11 @@ def synthesize_speech(request: TTSRequest):
89
 
90
  except Exception as e:
91
  print(f"Error during synthesis: {e}")
 
 
92
  raise HTTPException(
93
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
94
- detail="An error occurred during audio synthesis."
95
  )
96
 
97
  # --- 5. Add a Root Endpoint for Health Check ---
 
26
  models['hifigan'] = HifiGanModel.restore_from("models/hifigan_en.nemo").to(device)
27
  models['hifigan'].eval()
28
 
29
+ # Load the English Spectrogram Generator
30
  models['en'] = FastPitchModel.restore_from("models/fastpitch_en.nemo").to(device)
31
  models['en'].eval()
32
 
33
+ # Load the Bikol Spectrogram Generator with strict=False
34
+ # This allows loading even if there are size mismatches in embedding layers
35
+ models['bikol'] = FastPitchModel.restore_from(
36
+ "models/fastpitch_bikol_repacked.nemo",
37
+ strict=False # Critical: allows loading with different vocabulary size
38
+ ).to(device)
39
  models['bikol'].eval()
40
 
41
  print("All models loaded successfully.")
42
  except Exception as e:
43
  print(f"FATAL: Could not load models. Error: {e}")
44
+ import traceback
45
+ traceback.print_exc()
46
  # In a real app, you might want the app to fail fast if models can't load.
47
 
48
  # --- 3. Define API Request and Response Models ---
 
96
 
97
  except Exception as e:
98
  print(f"Error during synthesis: {e}")
99
+ import traceback
100
+ traceback.print_exc()
101
  raise HTTPException(
102
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
103
+ detail=f"An error occurred during audio synthesis: {str(e)}"
104
  )
105
 
106
  # --- 5. Add a Root Endpoint for Health Check ---