Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import gradio as gr | |
from youtube_dl import YoutubeDL | |
# Function to download audio from YouTube link | |
# def download_audio(youtube_link, output_path): | |
# ydl_opts = { | |
# "format": "bestaudio/best", | |
# "outtmpl": output_path, | |
# "postprocessors": [ | |
# { | |
# "key": "FFmpegExtractAudio", | |
# "preferredcodec": "mp3", | |
# "preferredquality": "192", | |
# } | |
# ], | |
# } | |
# with YoutubeDL(ydl_opts) as ydl: | |
# ydl.download([youtube_link]) | |
# def update_visibility(interface, input_type): | |
# if input_type == "audio": | |
# interface.set_visibility("audio_input", True) | |
# interface.set_visibility("youtube_input", False) | |
# elif input_type == "youtube": | |
# interface.set_visibility("audio_input", False) | |
# interface.set_visibility("youtube_input", True) | |
def transcribe_audio(input_type, audio_path): | |
if input_type == "Audio": | |
model = pipeline(model="SofiaK/checkpoints") | |
return model(audio_path)["text"] | |
with gr.Blocks() as demo: | |
radio = gr.Radio( | |
choices=["Audio", "Youtube"], label="Choose your input type", value="Audio" | |
) | |
audio_input = gr.Audio( | |
sources=["upload", "microphone"], | |
type="filepath", | |
label="Upload Audio, or speak in the microphone", | |
visible=True, | |
interactive=True, | |
) | |
youtube_input = gr.Textbox( | |
value="https://www.youtube.com/", | |
label="Youtube Link", | |
visible=False, | |
interactive=True, | |
) | |
btn = gr.Button( | |
"Transcript", | |
) | |
def make_visible(val): | |
audio_visible = val == "Audio" | |
return { | |
audio_input: {"visible": audio_visible, "__type__": "update"}, | |
youtube_input: {"visible": not audio_visible, "__type__": "update"}, | |
} | |
radio.change(make_visible, inputs=radio, outputs=[audio_input, youtube_input]) | |
output = gr.Text(label="Model output") | |
btn.click(fn=transcribe_audio, inputs=[radio, audio_input], outputs=output) | |
demo.launch() | |