Spaces:
Runtime error
Runtime error
Update app.py
Browse filescomparison between implementations
app.py
CHANGED
|
@@ -78,6 +78,24 @@ def save_transcription(yt_url, transcription):
|
|
| 78 |
json.dump({"url": yt_url, "transcription": transcription, "datetime": datetime.now().isoformat()}, f)
|
| 79 |
f.write("\n")
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
demo = gr.Blocks()
|
| 82 |
|
| 83 |
yt_transcribe_interface = gr.Interface(
|
|
@@ -96,7 +114,23 @@ yt_transcribe_interface = gr.Interface(
|
|
| 96 |
allow_flagging="never",
|
| 97 |
)
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
with demo:
|
| 100 |
-
gr.TabbedInterface([yt_transcribe_interface], ["YouTube"])
|
| 101 |
|
| 102 |
demo.queue().launch()
|
|
|
|
| 78 |
json.dump({"url": yt_url, "transcription": transcription, "datetime": datetime.now().isoformat()}, f)
|
| 79 |
f.write("\n")
|
| 80 |
|
| 81 |
+
@spaces.GPU
|
| 82 |
+
def yt_transcribe2(yt_url, task, max_filesize=75.0):
|
| 83 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
| 84 |
+
|
| 85 |
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 86 |
+
filepath = os.path.join(tmpdirname, "video.mp4")
|
| 87 |
+
download_yt_audio(yt_url, filepath)
|
| 88 |
+
with open(filepath, "rb") as f:
|
| 89 |
+
inputs = f.read()
|
| 90 |
+
|
| 91 |
+
inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
|
| 92 |
+
inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
|
| 93 |
+
|
| 94 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
| 95 |
+
|
| 96 |
+
return html_embed_str, text
|
| 97 |
+
|
| 98 |
+
|
| 99 |
demo = gr.Blocks()
|
| 100 |
|
| 101 |
yt_transcribe_interface = gr.Interface(
|
|
|
|
| 114 |
allow_flagging="never",
|
| 115 |
)
|
| 116 |
|
| 117 |
+
yt_transcribe = gr.Interface(
|
| 118 |
+
fn=yt_transcribe2,
|
| 119 |
+
inputs=[
|
| 120 |
+
gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
| 121 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
|
| 122 |
+
],
|
| 123 |
+
outputs=["html", "text"],
|
| 124 |
+
title="Whisper Large V3: Transcribe YouTube",
|
| 125 |
+
description=(
|
| 126 |
+
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
| 127 |
+
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
| 128 |
+
" arbitrary length."
|
| 129 |
+
),
|
| 130 |
+
allow_flagging="never",
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
with demo:
|
| 134 |
+
gr.TabbedInterface([yt_transcribe_interface, yt_transcribe], ["YouTube", "YouTube HF"])
|
| 135 |
|
| 136 |
demo.queue().launch()
|