|
|
|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
import nemo.collections.asr as nemo_asr |
|
|
|
asr_canary = nemo_asr.models.ASRModel.from_pretrained("nvidia/canary-1b-flash") |
|
|
|
asr_whisper = pipeline("automatic-speech-recognition", model="openai/whisper-small") |
|
|
|
|
|
def transcrire1(fpath): |
|
output = asr_whisper(fpath) |
|
return output["text"] |
|
|
|
|
|
def transcrire2(fpath, source_lang, target_lang): |
|
transcriptions = asr_canary.transcribe([fpath], |
|
source_lang = source_lang, target_lang = target_lang) |
|
text = transcriptions[0].text |
|
|
|
return text |
|
|
|
|
|
demo = gr.Blocks(theme='JohnSmith9982/small_and_pretty') |
|
|
|
mic_transcrire = gr.Interface( |
|
fn=transcrire1, |
|
inputs=gr.Audio(sources="microphone", |
|
type="filepath"), |
|
cache_examples=True, |
|
outputs=gr.Textbox(label="Transcription", |
|
lines=3), |
|
title = 'Transcrire par microphone - Whisper') |
|
|
|
|
|
fich_transcrire = gr.Interface( |
|
fn=transcrire1, |
|
inputs=gr.Audio(sources="upload", |
|
type="filepath"), |
|
outputs=gr.Textbox(label="Transcription", |
|
lines=3), |
|
title = 'Transcrire un fichier audio - Whisper' |
|
) |
|
|
|
|
|
mic_transcrire1 = gr.Interface( |
|
fn=transcrire2, |
|
inputs=[gr.Audio(sources="microphone",type="filepath"), |
|
gr.Dropdown(choices = ['fr', 'en'], label ='Source languge'), |
|
gr.Dropdown(choices = ['fr', 'en'], label = 'Target language')], |
|
cache_examples=True, |
|
outputs=gr.Textbox(label="Transcription", |
|
lines=3), |
|
title = 'Transcrire par microphone - Canary') |
|
|
|
|
|
fich_transcrire1 = gr.Interface( |
|
fn=transcrire2, |
|
inputs=[gr.Audio(sources="upload",type="filepath"), |
|
gr.Dropdown(choices = ['fr', 'en'], label ='Source languge'), |
|
gr.Dropdown(choices = ['fr', 'en'], label ='Target language')], |
|
outputs=gr.Textbox(label="Transcription", |
|
lines=3), |
|
title= 'Transcrire un fichier audio - Canary' |
|
) |
|
|
|
|
|
with demo: |
|
gr.TabbedInterface( |
|
[mic_transcrire, |
|
fich_transcrire, |
|
mic_transcrire1, |
|
fich_transcrire1], |
|
["Transcrire Microphone", |
|
"Transcrire Audio", |
|
"Transcrire Microphone", |
|
"Transcrire Audio"], |
|
) |
|
|
|
demo.launch() |