Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import tempfile
|
|
| 6 |
import os
|
| 7 |
import uuid
|
| 8 |
import scipy.io.wavfile
|
|
|
|
| 9 |
|
| 10 |
MODEL_NAME = "ylacombe/whisper-large-v3-turbo"
|
| 11 |
BATCH_SIZE = 8
|
|
@@ -21,20 +22,16 @@ pipe = pipeline(
|
|
| 21 |
@spaces.GPU
|
| 22 |
def transcribe(inputs, previous_transcription):
|
| 23 |
try:
|
| 24 |
-
# Generate a unique filename using UUID
|
| 25 |
-
filename = f"{uuid.uuid4().hex}.wav"
|
| 26 |
-
filepath = os.path.join(tempfile.gettempdir(), filename)
|
| 27 |
-
|
| 28 |
-
# Extract sample rate and audio data from the tuple
|
| 29 |
sample_rate, audio_data = inputs
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
previous_transcription += pipe(filepath, batch_size=BATCH_SIZE, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
return previous_transcription
|
| 40 |
except Exception as e:
|
|
|
|
| 6 |
import os
|
| 7 |
import uuid
|
| 8 |
import scipy.io.wavfile
|
| 9 |
+
import numpy as np
|
| 10 |
|
| 11 |
MODEL_NAME = "ylacombe/whisper-large-v3-turbo"
|
| 12 |
BATCH_SIZE = 8
|
|
|
|
| 22 |
@spaces.GPU
|
| 23 |
def transcribe(inputs, previous_transcription):
|
| 24 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
sample_rate, audio_data = inputs
|
| 26 |
|
| 27 |
+
# Convert audio data to a NumPy array
|
| 28 |
+
audio_data = np.frombuffer(audio_data, dtype=np.int16)
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
previous_transcription += pipe(audio_data,
|
| 31 |
+
batch_size=BATCH_SIZE,
|
| 32 |
+
generate_kwargs={"task": "transcribe"},
|
| 33 |
+
return_timestamps=True,
|
| 34 |
+
sampling_rate=sample_rate)["text"]
|
| 35 |
|
| 36 |
return previous_transcription
|
| 37 |
except Exception as e:
|