File size: 2,000 Bytes
6c226f9
 
5ded1e8
 
6c226f9
94f1c39
 
 
 
 
 
 
 
 
 
 
 
 
 
6c226f9
5ded1e8
 
a495c2a
6c226f9
5ded1e8
 
 
d959af8
5ded1e8
d959af8
3c0cd8e
5ded1e8
6c226f9
0db4cce
7097513
 
88ca9aa
5ded1e8
7097513
d63ae8a
 
6c226f9
de63ea3
b95b5ca
6c226f9
b95b5ca
 
6c226f9
 
 
d63ae8a
 
6c226f9
 
5ded1e8
a495c2a
5ded1e8
 
 
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
import gradio as gr

import os
from gradio_client import Client

def transcribe_audio(youtube_url: str, task: str = "transcribe", return_timestamps: bool = False, api_name: str = "/predict_2") -> dict:
    """
    Transcribe audio from a given YouTube URL using a specified model.
    Parameters:
    - youtube_url (str): The YouTube URL to transcribe.
    - task (str, optional): The task to perform. Default is "transcribe".
    - return_timestamps (bool, optional): Whether to return timestamps. Default is True.
    - api_name (str, optional): The API endpoint to use. Default is "/predict_2".
    Returns:
    - dict: The transcription result.
    """
    client = Client("https://sanchit-gandhi-whisper-jax.hf.space/")
    result = client.predict(youtube_url, task, return_timestamps, fn_index=7)
    return result



MODEL_NAME = "openai/whisper-large-v2"


demo = gr.Blocks()

EXAMPLES = [
    ["https://www.youtube.com/watch?v=H1YoNlz2LxA", "translate",False],
]


yt_transcribe = gr.Interface(
    fn=transcribe_audio,
    inputs=[
        gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
        gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
        gr.inputs.Checkbox(label="Return timestamps")
    ],
    outputs=[gr.outputs.HTML(label="Video"),
        gr.outputs.Textbox(label="Transcription").style(show_copy_button=True)],
    layout="horizontal",
    theme=gr.themes.Base(),
    title="Whisper Large V2: Transcribe YouTube",
    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",
    examples=EXAMPLES,
    cache_examples=False
)

with demo:
    gr.DuplicateButton()
    gr.TabbedInterface([yt_transcribe], [ "YouTube"])

demo.launch(enable_queue=True)