Spaces:
Running
Running
Commit
·
d3e5bcd
0
Parent(s):
Duplicate from juanpy/videoresumen
Browse filesCo-authored-by: Juan OP <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +63 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: VideoSummary
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.16.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
duplicated_from: juanpy/videoresumen
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tempfile import TemporaryDirectory
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
from pytube import YouTube
|
5 |
+
import whisper
|
6 |
+
from transformers import pipeline
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
|
10 |
+
def get_title(url: str) -> str:
|
11 |
+
"""Returns the title of the YouTube video at the given URL."""
|
12 |
+
yt = YouTube(url)
|
13 |
+
return f"**{yt.title}**"
|
14 |
+
|
15 |
+
|
16 |
+
def download_audio(url: str, path: str) -> None:
|
17 |
+
"""Downloads the audio from the YouTube video at the given URL and saves it to the specified path."""
|
18 |
+
yt = YouTube(url)
|
19 |
+
audio = yt.streams.filter(only_audio=True).first()
|
20 |
+
audio.download(output_path=path, filename="a.mp4")
|
21 |
+
|
22 |
+
|
23 |
+
def transcribe(path: str) -> List[str]:
|
24 |
+
"""Transcribes the audio file at the given path and returns the text."""
|
25 |
+
model = whisper.load_model("tiny")
|
26 |
+
transcription = model.transcribe(path, fp16=False)["text"]
|
27 |
+
transcription_chunks = [transcription[i : i + 1000] for i in range(0, len(transcription), 1000)]
|
28 |
+
return transcription_chunks
|
29 |
+
|
30 |
+
|
31 |
+
def summarize(transcription: List[str]) -> str:
|
32 |
+
"""Summarizes the given text and returns the summary."""
|
33 |
+
model = pipeline("summarization", model="facebook/bart-large-cnn")
|
34 |
+
summary_chunks = model(transcription, max_length=80, min_length=30)
|
35 |
+
summary = (" ".join([chunks["summary_text"] for chunks in summary_chunks]).strip().replace(" . ", ". "))
|
36 |
+
return summary
|
37 |
+
|
38 |
+
|
39 |
+
def execute_pipeline(url: str) -> str:
|
40 |
+
"""Generates a temporary directory and executes the pipeline to download, transcribe and summarize the video."""
|
41 |
+
with TemporaryDirectory(dir=".") as tmp_dir:
|
42 |
+
download_audio(url, tmp_dir)
|
43 |
+
result = transcribe(f"{tmp_dir}/a.mp4")
|
44 |
+
text = summarize(result)
|
45 |
+
return text
|
46 |
+
|
47 |
+
|
48 |
+
def main() -> None:
|
49 |
+
"""Generates the Gradio interface."""
|
50 |
+
with gr.Blocks(analytics_enabled=True, title="Summarize a video") as page:
|
51 |
+
gr.HTML('<h2 style="text-align:center"><span style="font-size:36px">Summarize a <strong>Youtube</strong> video</span></h2>')
|
52 |
+
url = gr.Textbox(label="Enter the URL:")
|
53 |
+
title = gr.Markdown()
|
54 |
+
output = gr.Textbox(label="Summary")
|
55 |
+
summarize_btn = gr.Button("Go!").style(full_width=False)
|
56 |
+
summarize_btn.click(fn=get_title, inputs=url, outputs=title)
|
57 |
+
summarize_btn.click(fn=execute_pipeline, inputs=url, outputs=output)
|
58 |
+
gr.Markdown("*Works best with videos under 10 minutes. It usually takes around 2-3 minutes to execute.*")
|
59 |
+
page.launch()
|
60 |
+
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.16.0
|
2 |
+
pytube==12.1.2
|
3 |
+
transformers==4.25.1
|
4 |
+
whisper @ git+https://github.com/openai/whisper.git@28769fcfe50755a817ab922a7bc83483159600a9
|
5 |
+
|