Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -133,18 +133,20 @@ if audio_bytes:
|
|
| 133 |
sound = sound.set_channels(1).set_frame_rate(16000)
|
| 134 |
|
| 135 |
samples = np.array(sound.get_array_of_samples()).astype(np.float32) / 32768.0
|
| 136 |
-
waveform = torch.tensor(samples).unsqueeze(0)
|
| 137 |
|
| 138 |
# Whisper preprocessing
|
| 139 |
input_features = processor(
|
| 140 |
waveform.squeeze(), sampling_rate=16000, return_tensors="pt"
|
| 141 |
-
).input_features
|
| 142 |
-
|
| 143 |
|
| 144 |
# ⚠️ First try WITHOUT forced_decoder_ids
|
| 145 |
try:
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
|
|
|
| 148 |
except Exception as e:
|
| 149 |
st.error(f"Whisper error: {e}")
|
| 150 |
transcription = ""
|
|
|
|
| 133 |
sound = sound.set_channels(1).set_frame_rate(16000)
|
| 134 |
|
| 135 |
samples = np.array(sound.get_array_of_samples()).astype(np.float32) / 32768.0
|
| 136 |
+
waveform = torch.tensor(samples, dtype=torch.float32).unsqueeze(0)
|
| 137 |
|
| 138 |
# Whisper preprocessing
|
| 139 |
input_features = processor(
|
| 140 |
waveform.squeeze(), sampling_rate=16000, return_tensors="pt"
|
| 141 |
+
).input_features.to(model.device)
|
|
|
|
| 142 |
|
| 143 |
# ⚠️ First try WITHOUT forced_decoder_ids
|
| 144 |
try:
|
| 145 |
+
# Force English transcription
|
| 146 |
+
forced_decoder_ids = processor.get_decoder_prompt_ids(language="en", task="transcribe")
|
| 147 |
+
predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
|
| 148 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 149 |
+
|
| 150 |
except Exception as e:
|
| 151 |
st.error(f"Whisper error: {e}")
|
| 152 |
transcription = ""
|