Existance's picture
Rename app.py to app1.py
3e0de48
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)