Yuvvan Talreja commited on
Commit
5b10e2d
·
1 Parent(s): dd0d525

Param issues

Browse files
Files changed (1) hide show
  1. fastapi_app.py +16 -28
fastapi_app.py CHANGED
@@ -87,36 +87,32 @@ def get_model(model_name):
87
  logging.info(f"Converting Xenova model {model_name} to {hf_model_name}")
88
 
89
  try:
90
- # Load the model using TensorFlow compatibility mode
91
- import tensorflow as tf
92
- logging.info(f"TensorFlow version: {tf.__version__}")
93
-
94
- # Configure pipeline with correct parameters to avoid conflicts
95
  models[model_name] = pipeline(
96
  "automatic-speech-recognition",
97
  model=hf_model_name,
98
  chunk_length_s=30,
99
- stride_length_s=5,
100
- framework="tf", # Explicitly use TensorFlow
101
- model_kwargs={
102
- "attention_mask": True, # Explicitly set attention mask
103
- "use_cache": True,
104
- }
105
  )
106
- logging.info(f"Model {model_name} loaded successfully with TensorFlow")
107
  except Exception as e:
108
- logging.error(f"Error loading model with TensorFlow: {str(e)}")
109
  try:
110
- # Fallback to PyTorch with more specific configurations
111
  from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
 
 
 
 
 
112
 
113
- # First load processor and model separately to customize configs
114
  processor = AutoProcessor.from_pretrained(hf_model_name)
115
  model = AutoModelForSpeechSeq2Seq.from_pretrained(
116
  hf_model_name,
117
  use_cache=True,
118
- attention_mask=True
119
- )
120
 
121
  # Create the pipeline with the initialized model and processor
122
  models[model_name] = pipeline(
@@ -126,11 +122,7 @@ def get_model(model_name):
126
  feature_extractor=processor,
127
  chunk_length_s=30,
128
  stride_length_s=5,
129
- generate_kwargs={
130
- "task": "transcribe",
131
- "language": "english",
132
- # Don't set forced_decoder_ids here to avoid conflict
133
- }
134
  )
135
  logging.info(f"Model {model_name} loaded successfully with PyTorch")
136
  except Exception as e2:
@@ -156,14 +148,10 @@ def process_audio(audio_data, sample_rate=16000, model_name="openai/whisper-base
156
 
157
  logging.info(f"Processing chunk {i+1}/{total_chunks}")
158
 
159
- # Use consistent parameters for model inference
160
  result = model(
161
  chunk,
162
- return_timestamps=True,
163
- generate_kwargs={
164
- "task": "transcribe",
165
- "language": "english"
166
- }
167
  )
168
 
169
  if "chunks" in result and len(result["chunks"]) > 0:
 
87
  logging.info(f"Converting Xenova model {model_name} to {hf_model_name}")
88
 
89
  try:
90
+ # Load the model using a simpler approach without problematic parameters
 
 
 
 
91
  models[model_name] = pipeline(
92
  "automatic-speech-recognition",
93
  model=hf_model_name,
94
  chunk_length_s=30,
95
+ stride_length_s=5
 
 
 
 
 
96
  )
97
+ logging.info(f"Model {model_name} loaded successfully with default settings")
98
  except Exception as e:
99
+ logging.error(f"Error loading model with default settings: {str(e)}")
100
  try:
101
+ # Fallback to explicit model loading if necessary
102
  from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
103
+ import torch
104
+
105
+ # Check device
106
+ device = "cuda" if torch.cuda.is_available() else "cpu"
107
+ logging.info(f"Using device: {device}")
108
 
109
+ # First load processor and model separately
110
  processor = AutoProcessor.from_pretrained(hf_model_name)
111
  model = AutoModelForSpeechSeq2Seq.from_pretrained(
112
  hf_model_name,
113
  use_cache=True,
114
+ low_cpu_mem_usage=True
115
+ ).to(device)
116
 
117
  # Create the pipeline with the initialized model and processor
118
  models[model_name] = pipeline(
 
122
  feature_extractor=processor,
123
  chunk_length_s=30,
124
  stride_length_s=5,
125
+ device=device
 
 
 
 
126
  )
127
  logging.info(f"Model {model_name} loaded successfully with PyTorch")
128
  except Exception as e2:
 
148
 
149
  logging.info(f"Processing chunk {i+1}/{total_chunks}")
150
 
151
+ # Use simpler parameters for model inference to avoid errors
152
  result = model(
153
  chunk,
154
+ return_timestamps=True
 
 
 
 
155
  )
156
 
157
  if "chunks" in result and len(result["chunks"]) > 0: