Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,21 +6,22 @@ def load_model(model_size):
|
|
6 |
model = WhisperModel(model_size, device="cpu", compute_type="int8")
|
7 |
return model
|
8 |
|
9 |
-
#
|
10 |
def transcribe_audio(model_size, audio_file):
|
11 |
# Initialize the model with the given size
|
12 |
model = load_model(model_size)
|
13 |
|
14 |
-
#
|
|
|
15 |
segments, info = model.transcribe(audio_file, beam_size=5)
|
|
|
|
|
|
|
16 |
|
17 |
-
#
|
18 |
-
transcribed_text = ""
|
19 |
for segment in segments:
|
20 |
transcribed_text += segment.text + " "
|
21 |
-
|
22 |
-
# Return detected language and transcribed text
|
23 |
-
return f"Detected language: {info.language} (Probability: {info.language_probability:.2f})", transcribed_text.strip()
|
24 |
|
25 |
# Define the Gradio interface
|
26 |
interface = gr.Interface(
|
@@ -34,7 +35,8 @@ interface = gr.Interface(
|
|
34 |
gr.Textbox(label="Transcription")
|
35 |
], # Output language and transcription
|
36 |
title="Whisper Transcription App",
|
37 |
-
description="Upload an audio file and specify the model size to transcribe it using WhisperModel."
|
|
|
38 |
)
|
39 |
|
40 |
# Launch the app
|
|
|
6 |
model = WhisperModel(model_size, device="cpu", compute_type="int8")
|
7 |
return model
|
8 |
|
9 |
+
# Streaming transcription function
|
10 |
def transcribe_audio(model_size, audio_file):
|
11 |
# Initialize the model with the given size
|
12 |
model = load_model(model_size)
|
13 |
|
14 |
+
# Stream the transcription of the audio file
|
15 |
+
transcribed_text = ""
|
16 |
segments, info = model.transcribe(audio_file, beam_size=5)
|
17 |
+
|
18 |
+
# Yield detected language information first
|
19 |
+
yield f"Detected language: {info.language} (Probability: {info.language_probability:.2f})", transcribed_text.strip()
|
20 |
|
21 |
+
# Then yield each segment of transcribed text as it is processed
|
|
|
22 |
for segment in segments:
|
23 |
transcribed_text += segment.text + " "
|
24 |
+
yield "", transcribed_text.strip() # Empty string for language, we only update transcription
|
|
|
|
|
25 |
|
26 |
# Define the Gradio interface
|
27 |
interface = gr.Interface(
|
|
|
35 |
gr.Textbox(label="Transcription")
|
36 |
], # Output language and transcription
|
37 |
title="Whisper Transcription App",
|
38 |
+
description="Upload an audio file and specify the model size to transcribe it using WhisperModel.",
|
39 |
+
live=True # Enable live updates
|
40 |
)
|
41 |
|
42 |
# Launch the app
|