import gradio as gr from asr import transcribe_multiple_files, ASR_LANGUAGES, model from lid import identify, LID_EXAMPLES from csv_processor import CSV_FILE_PATH import logging import soundfile as sf import os # Set up logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) def download_csv(): file_path = CSV_FILE_PATH # Путь к вашему файлу if os.path.exists(file_path): # Проверяем, существует ли файл return file_path # Если файл существует, возвращаем путь для скачивания else: logger.error(f"file {file_path} not found!") full_path = "/home/user/app/"+ file_path exist_full_path = os.path.exists(full_path) res = "found" if exist_full_path else "not found" logger.error(f"file {exist_full_path} {res}!") return None # Возвращаем None, если файла нет # Prepare language options for Dropdown language_options = [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()] bam_val = "bam (Bamanankan)" bam_index = 0 if bam_val not in language_options else language_options.index(bam_val) download_interface = gr.Interface( fn=download_csv, inputs=[], outputs=gr.File(label="Download CSV"), title="Download CSV file", description="Download file audio_plus_hash_uniq_07102024.csv" ) mms_transcribe = gr.Interface( fn=transcribe_multiple_files, inputs=[ gr.File(type="filepath"), # Allow multiple audio files gr.Dropdown( choices=language_options, label="Language", value=language_options[bam_index] if language_options else None, ), gr.Textbox(label="Optional: Provide your own transcription"), ], outputs=gr.Textbox(label="Transcriptions", lines=10), title="Speech-to-text", description="Transcribe multiple audio files in your desired language.", allow_flagging="never", ) mms_identify = gr.Interface( fn=identify, inputs=[gr.Audio()], outputs=gr.Label(num_top_classes=10), examples=LID_EXAMPLES, title="Language Identification", description="Identify the language of input audio.", allow_flagging="never", ) tabbed_interface = gr.TabbedInterface( [mms_transcribe, mms_identify, download_interface], ["Speech-to-text", "Language Identification", "Download CSV file"], ) with gr.Blocks() as demo: gr.Markdown( "
MMS: Scaling Speech Technology to 1000+ languages demo. See our blog post and paper.
" ) gr.HTML( """