Spaces:
Runtime error
Runtime error
from cProfile import label | |
from email.policy import default | |
from altair import value | |
import gradio as gr | |
import os | |
from lang_list import TEXT_SOURCE_LANGUAGE_NAMES | |
HF_API = os.getenv("HF_API") | |
API_URL = os.getenv("API_URL") # path to Seamlessm4t API endpoint | |
DEFAULT_TARGET_LANGUAGE = "Western Persian" | |
DESCRIPTION = """ | |
# Seamlessm4t + Speaker Diarization + Voice Activity Detection | |
Here we use seamlessm4t to generate captions for full audios. Audio can be of arbitrary length. | |
""" | |
DUPLICATE = """ | |
To duplicate this repo, you have to give permission from three reopsitories and accept all user conditions: | |
1- https://huggingface.co./pyannote/voice-activity-detection | |
2- https://hf.co/pyannote/segmentation | |
3- https://hf.co/pyannote/speaker-diarization | |
""" | |
def update_audio_ui(audio_source: str) -> tuple[dict, dict]: | |
mic = audio_source == "microphone" | |
return ( | |
gr.update(visible=mic, value=None), # input_audio_mic | |
gr.update(visible=not mic, value=None), # input_audio_file | |
) | |
with gr.Blocks(css="style.css") as demo: | |
gr.Markdown(DESCRIPTION) | |
with gr.Group(): | |
target_language = gr.Dropdown( | |
choices=TEXT_SOURCE_LANGUAGE_NAMES, | |
label="Output Language", | |
value=DEFAULT_TARGET_LANGUAGE, | |
interactive=True, | |
) | |
target_language.update(value=DEFAULT_TARGET_LANGUAGE) | |
with gr.Row() as audio_box: | |
audio_source = gr.Radio( | |
choices=["file", "microphone"], value="file", interactive=True | |
) | |
input_audio_mic = gr.Audio( | |
label="Input speech", | |
type="filepath", | |
source="microphone", | |
visible=False, | |
) | |
input_audio_file = gr.Audio( | |
label="Input speech", | |
type="filepath", | |
source="upload", | |
visible=True, | |
) | |
output = gr.Audio(label="Output", visible=False) | |
audio_source.change( | |
fn=update_audio_ui, | |
inputs=audio_source, | |
outputs=[input_audio_mic, input_audio_file], | |
queue=False, | |
api_name=False, | |
) | |
input_audio_mic.change(lambda x: x, input_audio_mic, output) | |
input_audio_file.change(lambda x: x, input_audio_file, output) | |
submit = gr.Button("Submit") | |
text_output = gr.Textbox(label="Transcribed Text", value="", interactive=False) | |
gr.Markdown(DUPLICATE) | |
demo.queue(max_size=50).launch() | |