File size: 2,130 Bytes
b41bc50
 
 
 
 
 
 
 
7f73c5b
 
b41bc50
 
 
 
 
 
 
 
 
3c9b0c2
b41bc50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c9b0c2
 
b41bc50
 
 
f2adc28
3c9b0c2
b41bc50
 
 
 
 
 
 
 
 
 
 
 
 
91ab95b
b41bc50
 
91ab95b
 
 
b41bc50
91ab95b
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import gradio as gr
import yt_dlp as youtube_dl
import tempfile
import os


YT_LENGTH_LIMIT_S = 3600
FILE_LIMIT_MB = 1000
MODEL_NAME = "Wisper"


def _return_yt_html_embed(yt_url):
    video_id = yt_url.split("?v=")[-1]
    HTML_str = (
        f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
        " </center>"
    )
    return HTML_str

def yt_transcribe(yt_url, max_filesize=75.0):
    html_embed_str = _return_yt_html_embed(yt_url)

    # with tempfile.TemporaryDirectory() as tmpdirname:
    #     filepath = os.path.join(tmpdirname, "video.mp4")
    #     download_yt_audio(yt_url, filepath)
    #     with open(filepath, "rb") as f:
    #         inputs = f.read()

    # inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
    # inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}

    # text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]

    return html_embed_str#, text

demo = gr.Blocks()

url = gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),

yt_transcribe = gr.Interface(
    fn=yt_transcribe,
    inputs=[
        # gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
        url
        # gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe")
    ],
    # outputs=["html", "text"],
    outputs=["html"],
    layout="horizontal",
    theme="huggingface",
    title="YouTube Video Viwer",
    description=(
        "Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
        f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
        " arbitrary length."
    ),
    allow_flagging="never",
).launch(enable_queue=True)


# with demo:
#     # gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
#     gr.TabbedInterface([yt_transcribe], ["YouTube"])

# demo.launch(enable_queue=True)