Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import yt_dlp as youtube_dl
|
3 |
+
import tempfile
|
4 |
+
import os
|
5 |
+
|
6 |
+
|
7 |
+
YT_LENGTH_LIMIT_S = 3600
|
8 |
+
FILE_LIMIT_MB = 1000
|
9 |
+
|
10 |
+
def _return_yt_html_embed(yt_url):
|
11 |
+
video_id = yt_url.split("?v=")[-1]
|
12 |
+
HTML_str = (
|
13 |
+
f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
|
14 |
+
" </center>"
|
15 |
+
)
|
16 |
+
return HTML_str
|
17 |
+
|
18 |
+
def yt_transcribe(yt_url, task, max_filesize=75.0):
|
19 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
20 |
+
|
21 |
+
# with tempfile.TemporaryDirectory() as tmpdirname:
|
22 |
+
# filepath = os.path.join(tmpdirname, "video.mp4")
|
23 |
+
# download_yt_audio(yt_url, filepath)
|
24 |
+
# with open(filepath, "rb") as f:
|
25 |
+
# inputs = f.read()
|
26 |
+
|
27 |
+
# inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
|
28 |
+
# inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
|
29 |
+
|
30 |
+
# text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
31 |
+
|
32 |
+
return html_embed_str#, text
|
33 |
+
|
34 |
+
demo = gr.Blocks()
|
35 |
+
|
36 |
+
yt_transcribe = gr.Interface(
|
37 |
+
fn=yt_transcribe,
|
38 |
+
inputs=[
|
39 |
+
gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
40 |
+
# gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe")
|
41 |
+
],
|
42 |
+
# outputs=["html", "text"],
|
43 |
+
outputs=["html"],
|
44 |
+
layout="horizontal",
|
45 |
+
theme="huggingface",
|
46 |
+
title="YouTube Video Viwer",
|
47 |
+
description=(
|
48 |
+
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
49 |
+
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
50 |
+
" arbitrary length."
|
51 |
+
),
|
52 |
+
allow_flagging="never",
|
53 |
+
)
|
54 |
+
|
55 |
+
|
56 |
+
with demo:
|
57 |
+
# gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
58 |
+
gr.TabbedInterface([yt_transcribe], ["YouTube"])
|
59 |
+
|
60 |
+
demo.launch(enable_queue=True)
|