import gradio as gr import librosa from asr import transcribe, ASR_EXAMPLES, ASR_LANGUAGES, ASR_NOTE from tts import synthesize, TTS_EXAMPLES, TTS_LANGUAGES from lid import identify, LID_EXAMPLES import os # Disable HF_HUB_ENABLE_HF_TRANSFER os.environ['HF_HUB_ENABLE_HF_TRANSFER'] = '0' def safe_transcribe(*args, **kwargs): try: return transcribe(*args, **kwargs) except Exception as e: return f"Error: {str(e)}" def safe_synthesize(*args, **kwargs): try: return synthesize(*args, **kwargs) except Exception as e: return f"Error: {str(e)}" def safe_identify(*args, **kwargs): try: return identify(*args, **kwargs) except Exception as e: return f"Error: {str(e)}" demo = gr.Blocks() mms_select_source_trans = gr.Radio( ["Tak upp", "Ljóðfíla"], label="Ljóð til talukennara", value="Tak upp", ) mms_mic_source_trans = gr.Audio(source="microphone", type="filepath", label="Brúka mikrofonina", visible=True) mms_upload_source_trans = gr.Audio( source="upload", type="filepath", label="Legg ljóðfílu upp", visible=False ) # Add back the language selection dropdown but set it to be hidden and default to Faroese asr_language_dropdown = gr.Dropdown( [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()], label="Mál", value="fao (Faroese)", visible=False, ) mms_transcribe = gr.Interface( fn=safe_transcribe, inputs=[ mms_select_source_trans, mms_mic_source_trans, mms_upload_source_trans, asr_language_dropdown, ], outputs="text", examples=ASR_EXAMPLES, title="Talukennari", description=( "Tak upp beinleiðis úr kaganum, ella legg eina ljóðfílu upp, og fá talukennaran at avskriva tað, ið verður sagt." ), article=ASR_NOTE, allow_flagging="never", ) # Add back the language selection dropdown but set it to be hidden and default to Faroese tts_language_dropdown = gr.Dropdown( [f"{k} ({v})" for k, v in TTS_LANGUAGES.items()], label="Mál", value="fao (Faroese)", visible=False, ) mms_synthesize = gr.Interface( fn=safe_synthesize, inputs=[ gr.Text(label="Tekstur at lesa upp"), tts_language_dropdown, gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Ferð"), ], outputs=[ gr.Audio(label="Ljóð frá teldutaluni", type="numpy"), gr.Text(label="Teksturin, sum verður lisin upp"), ], examples=TTS_EXAMPLES, title="Teldutala", description=("Fá tekstin lisnan upp við teldutalu."), allow_flagging="never", ) mms_select_source_iden = gr.Radio( ["Tak upp frá mikrofonini", "Vel ljóðfílu"], label="Audio input", value="Tak upp frá mikrofonini", ) mms_mic_source_iden = gr.Audio(source="microphone", type="filepath", label="Use mic", visible=True) mms_upload_source_iden = gr.Audio( source="upload", type="filepath", label="Upload file", visible=False ) mms_identify = gr.Interface( fn=safe_identify, inputs=[ mms_select_source_iden, mms_mic_source_iden, mms_upload_source_iden, ], outputs=gr.Label(num_top_classes=10), examples=LID_EXAMPLES, title="Máleyðmerkjari", description=("Tak upp ella legg eina ljóðfílu upp og fá máleyðmerkjaran at gita, hvat mál tú snakkar."), allow_flagging="never", ) tabbed_interface = gr.TabbedInterface( [mms_transcribe, mms_synthesize, mms_identify], ["Talukennari", "Teldutala", "Máleyðmerkjari"], ) with gr.Blocks() as demo: tabbed_interface.render() mms_select_source_trans.change( lambda x: [ gr.update(visible=True if x == "Tak upp" else False), gr.update(visible=True if x == "Ljóðfíla" else False), ], inputs=[mms_select_source_trans], outputs=[mms_mic_source_trans, mms_upload_source_trans], queue=False, ) mms_select_source_iden.change( lambda x: [ gr.update(visible=True if x == "Tak upp frá mikrofonini" else False), gr.update(visible=True if x == "Vel ljóðfílu" else False), ], inputs=[mms_select_source_iden], outputs=[mms_mic_source_iden, mms_upload_source_iden], queue=False, ) gr.HTML( """
""" ) demo.queue(concurrency_count=3) demo.launch()