Yuvvan Talreja commited on
Commit
adea0aa
·
1 Parent(s): 9c11e8c
Files changed (2) hide show
  1. Dockerfile +4 -4
  2. fastapi_app.py +10 -33
Dockerfile CHANGED
@@ -17,11 +17,11 @@ RUN pip install --no-cache-dir -r requirements.txt
17
  # Install additional dependencies directly
18
  RUN pip install --no-cache-dir sentence-transformers>=2.2.2
19
 
20
- # Download model files
21
  RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
22
- RUN python -c "from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq; \
23
- processor = AutoProcessor.from_pretrained('openai/whisper-base'); \
24
- model = AutoModelForSpeechSeq2Seq.from_pretrained('openai/whisper-base', from_tf=True)"
25
 
26
  # Run NLTK downloads
27
  RUN python -m nltk.downloader punkt wordnet
 
17
  # Install additional dependencies directly
18
  RUN pip install --no-cache-dir sentence-transformers>=2.2.2
19
 
20
+ # Download model files - only use the sentence transformer
21
  RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
22
+
23
+ # Skip Whisper model preloading - it will be downloaded on first use
24
+ # We don't need to preload it during build
25
 
26
  # Run NLTK downloads
27
  RUN python -m nltk.downloader punkt wordnet
fastapi_app.py CHANGED
@@ -87,36 +87,24 @@ def get_model(model_name):
87
  logging.info(f"Converting Xenova model {model_name} to {hf_model_name}")
88
 
89
  try:
90
- # First, try loading the model with from_tf=True
91
- from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, pipeline
92
-
93
- processor = AutoProcessor.from_pretrained(hf_model_name)
94
- model = AutoModelForSpeechSeq2Seq.from_pretrained(
95
- hf_model_name,
96
- from_tf=True,
97
- use_fast=True
98
- )
99
 
100
  models[model_name] = pipeline(
101
  "automatic-speech-recognition",
102
- model=model,
103
- tokenizer=processor,
104
- feature_extractor=processor,
105
  chunk_length_s=30,
106
  stride_length_s=5
107
  )
108
- logging.info(f"Model {model_name} loaded successfully with from_tf=True")
109
  except Exception as e:
110
- logging.error(f"Error loading model with from_tf=True, trying with from_tf=False: {str(e)}")
111
  try:
112
- # Fallback to regular loading method
113
  from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, pipeline
114
 
115
  processor = AutoProcessor.from_pretrained(hf_model_name)
116
- model = AutoModelForSpeechSeq2Seq.from_pretrained(
117
- hf_model_name,
118
- use_fast=True
119
- )
120
 
121
  models[model_name] = pipeline(
122
  "automatic-speech-recognition",
@@ -126,21 +114,10 @@ def get_model(model_name):
126
  chunk_length_s=30,
127
  stride_length_s=5
128
  )
129
- logging.info(f"Model {model_name} loaded successfully with from_tf=False")
130
  except Exception as e2:
131
- # Last resort: try direct pipeline with no extra args
132
- try:
133
- from transformers import pipeline
134
- models[model_name] = pipeline(
135
- "automatic-speech-recognition",
136
- hf_model_name,
137
- chunk_length_s=30,
138
- stride_length_s=5
139
- )
140
- logging.info(f"Model {model_name} loaded successfully with direct pipeline")
141
- except Exception as e3:
142
- logging.error(f"Failed to load model {model_name}: {str(e3)}")
143
- raise RuntimeError(f"Failed to load model {model_name}: {str(e3)}")
144
  return models[model_name]
145
 
146
  def process_audio(audio_data, sample_rate=16000, model_name="openai/whisper-base"):
 
87
  logging.info(f"Converting Xenova model {model_name} to {hf_model_name}")
88
 
89
  try:
90
+ # Simple direct approach without from_tf
91
+ from transformers import pipeline
 
 
 
 
 
 
 
92
 
93
  models[model_name] = pipeline(
94
  "automatic-speech-recognition",
95
+ hf_model_name,
 
 
96
  chunk_length_s=30,
97
  stride_length_s=5
98
  )
99
+ logging.info(f"Model {model_name} loaded successfully using direct pipeline")
100
  except Exception as e:
101
+ logging.error(f"Error loading model with direct pipeline: {str(e)}")
102
  try:
103
+ # Try with explicit loading but no from_tf
104
  from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, pipeline
105
 
106
  processor = AutoProcessor.from_pretrained(hf_model_name)
107
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(hf_model_name)
 
 
 
108
 
109
  models[model_name] = pipeline(
110
  "automatic-speech-recognition",
 
114
  chunk_length_s=30,
115
  stride_length_s=5
116
  )
117
+ logging.info(f"Model {model_name} loaded successfully with explicit loading")
118
  except Exception as e2:
119
+ logging.error(f"Failed to load model {model_name}: {str(e2)}")
120
+ raise RuntimeError(f"Failed to load model {model_name}: {str(e2)}")
 
 
 
 
 
 
 
 
 
 
 
121
  return models[model_name]
122
 
123
  def process_audio(audio_data, sample_rate=16000, model_name="openai/whisper-base"):