Commit
•
a69491c
0
Parent(s):
Duplicate from SteveDigital/free-fast-youtube-url-video-to-text-using-openai-whisper
Browse files- .gitattributes +34 -0
- README.md +14 -0
- app.py +61 -0
- requirements.txt +3 -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,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Free Youtube URL Video-to-Text Using OpenAI Whisper
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.11.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: gpl-3.0
|
11 |
+
duplicated_from: SteveDigital/free-fast-youtube-url-video-to-text-using-openai-whisper
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
from pytube import YouTube
|
3 |
+
import gradio as gr
|
4 |
+
import os
|
5 |
+
import re
|
6 |
+
import logging
|
7 |
+
|
8 |
+
logging.basicConfig(level=logging.INFO)
|
9 |
+
model = whisper.load_model("base")
|
10 |
+
|
11 |
+
def get_text(url):
|
12 |
+
#try:
|
13 |
+
if url != '':
|
14 |
+
output_text_transcribe = ''
|
15 |
+
|
16 |
+
yt = YouTube(url)
|
17 |
+
#video_length = yt.length --- doesn't work anymore - using byte file size of the audio file instead now
|
18 |
+
#if video_length < 5400:
|
19 |
+
video = yt.streams.filter(only_audio=True).first()
|
20 |
+
out_file=video.download(output_path=".")
|
21 |
+
|
22 |
+
file_stats = os.stat(out_file)
|
23 |
+
logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
|
24 |
+
|
25 |
+
if file_stats.st_size <= 30000000:
|
26 |
+
base, ext = os.path.splitext(out_file)
|
27 |
+
new_file = base+'.mp3'
|
28 |
+
os.rename(out_file, new_file)
|
29 |
+
a = new_file
|
30 |
+
|
31 |
+
result = model.transcribe(a)
|
32 |
+
return result['text'].strip()
|
33 |
+
else:
|
34 |
+
logging.error('Videos for transcription on this space are limited to about 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos. Please visit https://steve.digital to contact me about this space.')
|
35 |
+
#finally:
|
36 |
+
# raise gr.Error("Exception: There was a problem transcribing the audio.")
|
37 |
+
|
38 |
+
def get_summary(article):
|
39 |
+
first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
|
40 |
+
b = summarizer(first_sentences, min_length = 20, max_length = 120, do_sample = False)
|
41 |
+
b = b[0]['summary_text'].replace(' .', '.').strip()
|
42 |
+
return b
|
43 |
+
|
44 |
+
with gr.Blocks() as demo:
|
45 |
+
gr.Markdown("<h1><center>Free Fast YouTube URL Video-to-Text using <a href=https://openai.com/blog/whisper/ target=_blank>OpenAI's Whisper</a> Model</center></h1>")
|
46 |
+
#gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video and then create a summary of the video transcript.</center>")
|
47 |
+
gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video.</center>")
|
48 |
+
gr.Markdown("<center><b>'Whisper is a neural net that approaches human level robustness and accuracy on English speech recognition.'</b></center>")
|
49 |
+
gr.Markdown("<center>Transcription takes 5-10 seconds per minute of the video (bad audio/hard accents slow it down a bit). #patience<br />If you have time while waiting, drop a ♥️ and check out my <a href=https://www.artificial-intelligence.blog target=_blank>AI blog</a> (opens in new tab).</center>")
|
50 |
+
|
51 |
+
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='YouTube URL')
|
52 |
+
result_button_transcribe = gr.Button('Transcribe')
|
53 |
+
output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
|
54 |
+
|
55 |
+
#result_button_summary = gr.Button('2. Create Summary')
|
56 |
+
#output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
|
57 |
+
|
58 |
+
result_button_transcribe.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
|
59 |
+
#result_button_summary.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)
|
60 |
+
|
61 |
+
demo.queue(default_enabled = True).launch(debug = True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/openai/whisper.git
|
2 |
+
transformers
|
3 |
+
pytube
|