cuhgrel commited on
Commit
793ce85
·
1 Parent(s): 5ed11a5

updated the app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -56
app.py CHANGED
@@ -5,7 +5,8 @@ import logging
5
  from fastapi import FastAPI, HTTPException, status
6
  from pydantic import BaseModel
7
  from nemo.collections.tts.models import FastPitchModel, HifiGanModel
8
- from omegaconf import OmegaConf, open_dict
 
9
 
10
  # Configure logging
11
  logging.basicConfig(level=logging.INFO)
@@ -39,65 +40,22 @@ def load_models():
39
  models['en'].eval()
40
  logger.info("English model loaded successfully")
41
 
42
- # Load the Bikol Spectrogram Generator with configuration override
43
  logger.info("Loading Bikol FastPitch model...")
44
- try:
45
- # First attempt: Try loading with strict=False
46
- models['bikol'] = FastPitchModel.restore_from(
47
- "models/fastpitch_bikol_fixed.nemo",
48
- strict=False
49
- ).to(device)
50
- models['bikol'].eval()
51
- logger.info("Bikol model loaded successfully")
52
-
53
- except Exception as e:
54
- logger.warning(f"First attempt failed: {e}")
55
- logger.info("Attempting to load Bikol model with config override...")
56
-
57
- # Second attempt: Override the text_tokenizer config to remove g2p parameter
58
- try:
59
- # Create a config override that removes the problematic g2p parameter
60
- override_config = OmegaConf.create({
61
- 'text_tokenizer': {
62
- '_target_': 'nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers.BaseCharsTokenizer',
63
- 'pad_with_space': True
64
- }
65
- })
66
-
67
- models['bikol'] = FastPitchModel.restore_from(
68
- "models/fastpitch_bikol_fixed.nemo",
69
- override_config_path=override_config,
70
- strict=False
71
- ).to(device)
72
- models['bikol'].eval()
73
- logger.info("Bikol model loaded successfully with config override")
74
-
75
- except Exception as e2:
76
- logger.error(f"Failed to load Bikol model with override: {e2}")
77
- # Third attempt: Try modifying the saved config
78
- logger.info("Attempting alternative loading method...")
79
-
80
- try:
81
- # Load model with map_location to avoid device issues
82
- models['bikol'] = FastPitchModel.restore_from(
83
- "models/fastpitch_bikol_fixed.nemo",
84
- map_location=device,
85
- strict=False
86
- )
87
- models['bikol'].eval()
88
- logger.info("Bikol model loaded with map_location")
89
- except Exception as e3:
90
- logger.error(f"All attempts to load Bikol model failed: {e3}")
91
- logger.error("Bikol language will not be available")
92
- # Don't raise - allow app to start with just English
93
-
94
- logger.info("Model loading complete. Available models: " + ", ".join(models.keys()))
95
-
96
  except Exception as e:
97
  logger.error(f"FATAL: Could not load models. Error: {e}")
98
  import traceback
99
  traceback.print_exc()
100
- # Allow app to start even if models fail - better for debugging
 
 
 
 
101
 
102
  # --- 3. Define API Request and Response Models ---
103
  class TTSRequest(BaseModel):
@@ -110,7 +68,7 @@ def synthesize_speech(request: TTSRequest):
110
  """
111
  Generates speech from text using the selected language model.
112
  """
113
- if not models:
114
  raise HTTPException(
115
  status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
116
  detail="Models are not loaded yet. Please try again in a moment."
 
5
  from fastapi import FastAPI, HTTPException, status
6
  from pydantic import BaseModel
7
  from nemo.collections.tts.models import FastPitchModel, HifiGanModel
8
+ # Omegaconf is no longer needed here since we aren't creating overrides
9
+ # from omegaconf import OmegaConf, open_dict
10
 
11
  # Configure logging
12
  logging.basicConfig(level=logging.INFO)
 
40
  models['en'].eval()
41
  logger.info("English model loaded successfully")
42
 
43
+ # Load the CORRECTED Bikol Spectrogram Generator
44
  logger.info("Loading Bikol FastPitch model...")
45
+ # This is the only line needed now. Replace the filename with your new .nemo file.
46
+ models['bikol'] = FastPitchModel.restore_from("models/fastpitch_bikol_corrected.nemo").to(device)
47
+ models['bikol'].eval()
48
+ logger.info("Bikol model loaded successfully")
49
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  except Exception as e:
51
  logger.error(f"FATAL: Could not load models. Error: {e}")
52
  import traceback
53
  traceback.print_exc()
54
+ # You might want the app to fail completely if models don't load
55
+ # raise e
56
+
57
+ logger.info("Model loading complete. Available models: " + ", ".join(models.keys()))
58
+
59
 
60
  # --- 3. Define API Request and Response Models ---
61
  class TTSRequest(BaseModel):
 
68
  """
69
  Generates speech from text using the selected language model.
70
  """
71
+ if not models or 'hifigan' not in models:
72
  raise HTTPException(
73
  status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
74
  detail="Models are not loaded yet. Please try again in a moment."