Spaces:
Running
Running
File size: 1,157 Bytes
346ee80 d522094 346ee80 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import whisper
model = whisper.load_model("base")
import deepl
deepl_auth_key = os.environ["Deepl_API"]
def translate(text, target_lang):
translator = deepl.Translator(deepl_auth_key)
translated_text = translator.translate_text(text, target_lang=target_lang)
return translated_text
def transcribe(audio):
# load audio and pad/trim it to fit 30 seconds
audio = whisper.load_audio(audio)
audio = whisper.pad_or_trim(audio)
# make log-Mel spectrogram and move to the same device as the model
mel = whisper.log_mel_spectrogram(audio).to(model.device)
# detect the spoken language
_, probs = model.detect_language(mel)
print(f"Detected language: {max(probs, key=probs.get)}")
detect_lang = max(probs, key=probs.get)
# decode the audio
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)
translated_text = translate(result.text, "JA")
return translated_text
import gradio as gr
title = 'Video Translator'
inputs = gr.Video()
outputs = gr.Text()
interface = gr.Interface(title=title, fn=transcribe, inputs=inputs, outputs=outputs)
interface.launch(debug=True)
|