Spaces:
Runtime error
Runtime error
Added translation form any to en
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import whisper
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
model = whisper.load_model("
|
| 5 |
|
| 6 |
def transcribe(audio):
|
| 7 |
|
|
@@ -14,18 +14,20 @@ def transcribe(audio):
|
|
| 14 |
|
| 15 |
# detect the spoken language
|
| 16 |
_, probs = model.detect_language(mel)
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# decode the audio
|
| 21 |
-
options = whisper.DecodingOptions(fp16 = False, language=
|
| 22 |
result = whisper.decode(model, mel, options)
|
| 23 |
return result.text
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
gr.Interface(
|
| 28 |
-
title = '
|
| 29 |
fn=transcribe,
|
| 30 |
inputs=[
|
| 31 |
gr.inputs.Audio(source="microphone", type="filepath")
|
|
|
|
| 1 |
import whisper
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
model = whisper.load_model("medium")
|
| 5 |
|
| 6 |
def transcribe(audio):
|
| 7 |
|
|
|
|
| 14 |
|
| 15 |
# detect the spoken language
|
| 16 |
_, probs = model.detect_language(mel)
|
| 17 |
+
|
| 18 |
+
detected_language = max(probs, key=probs.get)
|
| 19 |
+
task = 'transcribe' if detected_language == 'en' else 'translate'
|
| 20 |
+
|
| 21 |
+
print(f"Detected language: {detected_language}")
|
| 22 |
|
| 23 |
# decode the audio
|
| 24 |
+
options = whisper.DecodingOptions(task = task, fp16 = False, language=detected_language)
|
| 25 |
result = whisper.decode(model, mel, options)
|
| 26 |
return result.text
|
| 27 |
|
|
|
|
| 28 |
|
| 29 |
gr.Interface(
|
| 30 |
+
title = 'Whisper ASR With Auto Punctuation and Auto Translation Into En',
|
| 31 |
fn=transcribe,
|
| 32 |
inputs=[
|
| 33 |
gr.inputs.Audio(source="microphone", type="filepath")
|