Spaces:
Runtime error
Runtime error
Commit
·
7dd7859
1
Parent(s):
6095eda
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,10 +12,33 @@ whisper_model = whisper.load_model("small")
|
|
| 12 |
|
| 13 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
return "Hello " + name + "!!"
|
| 19 |
|
| 20 |
-
iface = gr.Interface(fn=
|
| 21 |
iface.launch()
|
|
|
|
| 12 |
|
| 13 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
| 15 |
+
def translate(audio):
|
| 16 |
+
print("""
|
| 17 |
+
—
|
| 18 |
+
Sending audio to Whisper ...
|
| 19 |
+
—
|
| 20 |
+
""")
|
| 21 |
+
audio = whisper.load_audio(audio)
|
| 22 |
+
audio = whisper.pad_or_trim(audio)
|
| 23 |
+
|
| 24 |
+
mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device)
|
| 25 |
+
|
| 26 |
+
_, probs = whisper_model.detect_language(mel)
|
| 27 |
+
|
| 28 |
+
transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False)
|
| 29 |
+
translate_options = whisper.DecodingOptions(task="translate", fp16 = False)
|
| 30 |
+
|
| 31 |
+
transcription = whisper.decode(whisper_model, mel, transcript_options)
|
| 32 |
+
translation = whisper.decode(whisper_model, mel, translate_options)
|
| 33 |
+
|
| 34 |
+
print("Language Spoken: " + transcription.language)
|
| 35 |
+
print("Transcript: " + transcription.text)
|
| 36 |
+
print("Translated: " + translation.text)
|
| 37 |
+
|
| 38 |
+
return transcription.language
|
| 39 |
+
|
| 40 |
|
| 41 |
+
record_input = gr.Audio(source="microphone",type="filepath", show_label=False)
|
|
|
|
| 42 |
|
| 43 |
+
iface = gr.Interface(fn=translate, inputs=record_input, outputs="text")
|
| 44 |
iface.launch()
|