SteveDigital
commited on
Commit
·
e3b3ac8
1
Parent(s):
047546f
Update app.py
Browse files
app.py
CHANGED
@@ -14,42 +14,39 @@ def get_text(url):
|
|
14 |
output_text_transcribe = ''
|
15 |
|
16 |
yt = YouTube(url)
|
17 |
-
#video_length = yt.length
|
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
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
result = model.transcribe(a)
|
31 |
-
return result['text'].strip()
|
32 |
-
#else:
|
33 |
-
# return "Videos for transcription on this space are limited to 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."
|
34 |
#finally:
|
35 |
# raise gr.Error("Exception: There was a problem transcribing the audio.")
|
36 |
|
37 |
def get_summary(article):
|
38 |
-
#try:
|
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 |
-
#finally:
|
44 |
-
#raise gr.Error("Exception: There was a problem summarizing the transcript.")
|
45 |
|
46 |
-
|
47 |
with gr.Blocks() as demo:
|
48 |
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>")
|
49 |
#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>")
|
50 |
gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video.</center>")
|
51 |
gr.Markdown("<center><b>'Whisper is a neural net that approaches human level robustness and accuracy on English speech recognition.'</b></center>")
|
52 |
-
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, check out my <a href=https://www.artificial-intelligence.blog target=_blank>AI blog</a> (opens in new tab).</center>")
|
53 |
|
54 |
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
|
55 |
result_button_transcribe = gr.Button('1. Transcribe')
|
|
|
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 |
+
if file_stats.st_size <= 20000000
|
23 |
+
file_stats = os.stat(out_file)
|
24 |
+
logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
|
25 |
+
|
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='URL')
|
52 |
result_button_transcribe = gr.Button('1. Transcribe')
|