Spaces:
Sleeping
Sleeping
File size: 1,386 Bytes
c494b72 efc0dfb 1ffba96 efc0dfb 1ffba96 c494b72 efc0dfb 1ffba96 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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])
# Function to transcribe audio
def transcribe_audio(audio_path):
model = pipeline(model="SofiaK/checkpoints")
return model(audio_path)["text"]
interface = gr.Interface(
fn=lambda input_type, audio_or_link: transcribe_audio(audio_or_link)
if input_type == "audio"
else transcribe_audio(download_audio(audio_or_link, "temp.mp3")),
inputs=[
gr.Radio(["audio", "youtube"], label="Select Input Type"),
gr.Audio(
sources=["upload", "microphone"],
type="filepath",
label="Upload Audio, or speak in the microphone",
),
gr.Textbox(default="https://www.youtube.com/", label="Youtube Link"),
],
outputs=gr.Text(label="Model output"),
title="Whisper-RU",
description="Fine-tuned Whisper for Russian language",
)
interface.launch(share=True)
|