CoolFace
Apppublic

saepulid/MULTIMEDIA

sourceHugging Facecc-by-nc-4.0updated 2y agoView on Hugging Face
4likes
app.py95 linesDownload Raw Back to root
1import gradio as gr2import librosa3from asr import transcribe, ASR_EXAMPLES, ASR_LANGUAGES, ASR_NOTE4from tts import synthesize, TTS_EXAMPLES, TTS_LANGUAGES5from lid import identify, LID_EXAMPLES6 7 8 9mms_transcribe = gr.Interface(10    fn=transcribe,11    inputs=[12        gr.Audio(),13        gr.Dropdown(14            [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()],15            label="Language",16            value="eng English",17        ),18        # gr.Checkbox(label="Use Language Model (if available)", default=True),19    ],20    outputs="text",21    examples=ASR_EXAMPLES,22    title="Speech-to-text",23    description=(24        "Transcribe audio from a microphone or input file in your desired language."25    ),26    article=ASR_NOTE,27    allow_flagging="never",28)29 30mms_synthesize = gr.Interface(31    fn=synthesize,32    inputs=[33        gr.Text(label="Input text"),34        gr.Dropdown(35            [f"{k} ({v})" for k, v in TTS_LANGUAGES.items()],36            label="Language",37            value="eng English",38        ),39        gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Speed"),40    ],41    outputs=[42        gr.Audio(label="Generated Audio", type="numpy"),43        gr.Text(label="Filtered text after removing OOVs"),44    ],45    examples=TTS_EXAMPLES,46    title="Text-to-speech",47    description=("Generate audio in your desired language from input text."),48    allow_flagging="never",49)50 51mms_identify = gr.Interface(52    fn=identify,53    inputs=[54        gr.Audio(),55    ],56    outputs=gr.Label(num_top_classes=10),57    examples=LID_EXAMPLES,58    title="Language Identification",59    description=("Identity the language of input audio."),60    allow_flagging="never",61)62 63tabbed_interface = gr.TabbedInterface(64    [mms_transcribe, mms_synthesize, mms_identify],65    ["Speech-to-text", "Text-to-speech", "Language Identification"],66)67 68with gr.Blocks() as demo:69    gr.Markdown(70        "<p align='center' style='font-size: 20px;'>MMS: Scaling Speech Technology to 1000+ languages demo. See our <a href='https://ai.facebook.com/blog/multilingual-model-speech-recognition/'>blog post</a> and <a href='https://arxiv.org/abs/2305.13516'>paper</a>.</p>"71    )72    gr.HTML(73        """<center>Click on the appropriate tab to explore Speech-to-text (ASR), Text-to-speech (TTS) and Language identification (LID) demos.   </center>"""74    )75    gr.HTML(76        """<center>You can also finetune MMS models on your data using the recipes provides here - <a href='https://huggingface.co/blog/mms_adapters'>ASR</a> <a href='https://github.com/ylacombe/finetune-hf-vits'>TTS</a>  </center>"""77    )78    gr.HTML(79        """<center><a href="https://huggingface.co/spaces/facebook/MMS?duplicate=true"  style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank"><img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a> for more control and no queue.</center>"""80    )81 82    tabbed_interface.render()83    gr.HTML(84        """85            <div class="footer" style="text-align:center">86                <p>87                    Model by <a href="https://ai.facebook.com" style="text-decoration: underline;" target="_blank">Meta AI</a> - Gradio Demo by 🤗 Hugging Face88                </p>89            </div>90           """91    )92 93if __name__ == "__main__":94    demo.queue()95    demo.launch()