Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
-
import torch
|
4 |
-
import gc
|
5 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
6 |
-
import tempfile
|
7 |
import yt_dlp
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
ydl.download([url])
|
26 |
-
return output_path.replace('%(ext)s', 'mp3')
|
27 |
|
28 |
-
def process_video(url
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
if len(text.strip()) < 50:
|
34 |
-
return "Transcription too short or unclear"
|
35 |
-
gc.collect()
|
36 |
-
if torch.cuda.is_available():
|
37 |
-
torch.cuda.empty_cache()
|
38 |
-
summary_result = summarizer(text, max_length=150, min_length=50, do_sample=False)
|
39 |
-
return summary_result[0]['summary_text']
|
40 |
|
41 |
def main(url):
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
import yt_dlp
|
3 |
+
import whisper
|
4 |
+
import tempfile
|
5 |
|
6 |
+
def download_audio(url, cookies_path):
|
7 |
+
with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as tmpfile:
|
8 |
+
ydl_opts = {
|
9 |
+
'format': 'bestaudio/best',
|
10 |
+
'outtmpl': tmpfile.name,
|
11 |
+
'quiet': True,
|
12 |
+
'cookiefile': cookies_path,
|
13 |
+
'postprocessors': [{
|
14 |
+
'key': 'FFmpegExtractAudio',
|
15 |
+
'preferredcodec': 'mp3',
|
16 |
+
'preferredquality': '192',
|
17 |
+
}]
|
18 |
+
}
|
19 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
20 |
+
ydl.download([url])
|
21 |
+
return tmpfile.name
|
|
|
|
|
22 |
|
23 |
+
def process_video(url, cookies_path):
|
24 |
+
audio_file = download_audio(url, cookies_path)
|
25 |
+
model = whisper.load_model("base")
|
26 |
+
result = model.transcribe(audio_file)
|
27 |
+
return result['text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def main(url):
|
30 |
+
cookies_path = 'cookies.txt' # Provide path to your exported cookies file
|
31 |
+
transcript = process_video(url, cookies_path)
|
32 |
+
return transcript
|
33 |
+
|
34 |
+
demo = gr.Interface(fn=main, inputs=gr.Textbox(label="YouTube URL"), outputs="text")
|
35 |
|
36 |
+
demo.launch()
|
|