nexusbert commited on
Commit
fc4d065
·
1 Parent(s): 986c194

gated model

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -5
  2. app.py +7 -3
Dockerfile CHANGED
@@ -33,16 +33,14 @@ ENV HF_HOME=/models/huggingface \
33
  # Created cache dir and set permissions
34
  RUN mkdir -p /models/huggingface && chmod -R 777 /models/huggingface
35
 
36
- # Pre-download models at build time (split into smaller chunks to avoid memory issues)
37
  RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/mms-tts-hau')" \
38
  && python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/mms-tts-eng')" \
39
  && python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/mms-tts-yor')" \
40
- && python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='NCAIR1/Igbo-ASR')" \
41
  && find /models/huggingface -name '*.lock' -delete
42
 
43
- # Preload tokenizers (avoid runtime delays) - MMS will be lazy-loaded
44
- RUN python -c "from transformers import WhisperProcessor; WhisperProcessor.from_pretrained('NCAIR1/Igbo-ASR')" \
45
- && python -c "from transformers import pipeline; pipeline('text-to-speech', model='facebook/mms-tts-hau')" \
46
  && python -c "from transformers import pipeline; pipeline('text-to-speech', model='facebook/mms-tts-eng')" \
47
  && python -c "from transformers import pipeline; pipeline('text-to-speech', model='facebook/mms-tts-yor')"
48
 
 
33
  # Created cache dir and set permissions
34
  RUN mkdir -p /models/huggingface && chmod -R 777 /models/huggingface
35
 
36
+ # Pre-download models at build time (only non-gated models)
37
  RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/mms-tts-hau')" \
38
  && python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/mms-tts-eng')" \
39
  && python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/mms-tts-yor')" \
 
40
  && find /models/huggingface -name '*.lock' -delete
41
 
42
+ # Preload tokenizers (avoid runtime delays) - MMS and Igbo ASR will be lazy-loaded
43
+ RUN python -c "from transformers import pipeline; pipeline('text-to-speech', model='facebook/mms-tts-hau')" \
 
44
  && python -c "from transformers import pipeline; pipeline('text-to-speech', model='facebook/mms-tts-eng')" \
45
  && python -c "from transformers import pipeline; pipeline('text-to-speech', model='facebook/mms-tts-yor')"
46
 
app.py CHANGED
@@ -102,17 +102,21 @@ def _get_igbo_asr():
102
  return igbo_model, igbo_processor
103
 
104
  hf_token = os.getenv("HF_TOKEN")
 
 
 
 
105
  try:
106
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
107
- logger.info("Lazy-loading Igbo ASR model...")
108
  igbo_processor = WhisperProcessor.from_pretrained("NCAIR1/Igbo-ASR", token=hf_token)
109
  igbo_model = WhisperForConditionalGeneration.from_pretrained("NCAIR1/Igbo-ASR", token=hf_token)
110
  igbo_model.to(device)
111
  igbo_model.eval()
112
  logger.info("Loaded Igbo ASR model")
113
  return igbo_model, igbo_processor
114
- except Exception:
115
- logger.exception("Failed to load Igbo ASR model")
116
  igbo_model, igbo_processor = None, None
117
  def _run_whisper(model: WhisperForConditionalGeneration, proc: WhisperProcessor, audio_array: np.ndarray) -> str:
118
  try:
 
102
  return igbo_model, igbo_processor
103
 
104
  hf_token = os.getenv("HF_TOKEN")
105
+ if not hf_token:
106
+ logger.warning("HF_TOKEN not set - Igbo ASR model requires authentication")
107
+ return None, None
108
+
109
  try:
110
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
111
+ logger.info("Lazy-loading Igbo ASR model (gated model)...")
112
  igbo_processor = WhisperProcessor.from_pretrained("NCAIR1/Igbo-ASR", token=hf_token)
113
  igbo_model = WhisperForConditionalGeneration.from_pretrained("NCAIR1/Igbo-ASR", token=hf_token)
114
  igbo_model.to(device)
115
  igbo_model.eval()
116
  logger.info("Loaded Igbo ASR model")
117
  return igbo_model, igbo_processor
118
+ except Exception as e:
119
+ logger.exception(f"Failed to load Igbo ASR model: {e}")
120
  igbo_model, igbo_processor = None, None
121
  def _run_whisper(model: WhisperForConditionalGeneration, proc: WhisperProcessor, audio_array: np.ndarray) -> str:
122
  try: