Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
from transformers import pipeline
|
| 5 |
import tempfile
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
MODEL_NAME = "ylacombe/whisper-large-v3-turbo"
|
| 9 |
BATCH_SIZE = 8
|
|
@@ -18,14 +19,30 @@ pipe = pipeline(
|
|
| 18 |
|
| 19 |
@spaces.GPU
|
| 20 |
def transcribe(inputs, previous_transcription):
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
with gr.Column():
|
| 26 |
input_audio_microphone = gr.Audio(streaming=True)
|
| 27 |
output = gr.Textbox(label="Transcription", value="")
|
| 28 |
-
|
| 29 |
-
input_audio_microphone.stream(transcribe, [input_audio_microphone, output], [output], time_limit=45, stream_every=
|
| 30 |
|
| 31 |
demo.queue().launch()
|
|
|
|
| 4 |
from transformers import pipeline
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
+
import uuid
|
| 8 |
|
| 9 |
MODEL_NAME = "ylacombe/whisper-large-v3-turbo"
|
| 10 |
BATCH_SIZE = 8
|
|
|
|
| 19 |
|
| 20 |
@spaces.GPU
|
| 21 |
def transcribe(inputs, previous_transcription):
|
| 22 |
+
try:
|
| 23 |
+
# Generate a unique filename using UUID
|
| 24 |
+
filename = f"{uuid.uuid4().hex}.wav"
|
| 25 |
+
filepath = os.path.join(tempfile.gettempdir(), filename)
|
| 26 |
+
|
| 27 |
+
# Save the audio data to the temporary file
|
| 28 |
+
with open(filepath, "wb") as f:
|
| 29 |
+
f.write(inputs[1])
|
| 30 |
+
|
| 31 |
+
previous_transcription += pipe(filepath, batch_size=BATCH_SIZE, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"]
|
| 32 |
+
|
| 33 |
+
# Remove the temporary file after transcription
|
| 34 |
+
os.remove(filepath)
|
| 35 |
+
|
| 36 |
+
return previous_transcription
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"Error during transcription: {e}")
|
| 39 |
+
return previous_transcription # Return the current transcription if an error occurs
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
with gr.Column():
|
| 43 |
input_audio_microphone = gr.Audio(streaming=True)
|
| 44 |
output = gr.Textbox(label="Transcription", value="")
|
| 45 |
+
|
| 46 |
+
input_audio_microphone.stream(transcribe, [input_audio_microphone, output], [output], time_limit=45, stream_every=2, concurrency_limit=None)
|
| 47 |
|
| 48 |
demo.queue().launch()
|