Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,13 @@ def get_audio(url):
|
|
11 |
ydl_opts = {
|
12 |
'format': 'bestaudio/best',
|
13 |
'noplaylist': True,
|
14 |
-
'quiet': True
|
|
|
15 |
}
|
16 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
17 |
info = ydl.extract_info(url, download=True)
|
18 |
-
# Use '
|
19 |
-
audio_file = info
|
20 |
return audio_file
|
21 |
except Exception as e:
|
22 |
raise gr.Error(f"Exception: {e}")
|
@@ -35,18 +36,12 @@ def get_text(url):
|
|
35 |
def get_summary(article):
|
36 |
try:
|
37 |
first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
|
38 |
-
# Assuming you have a summarizer pipeline set up
|
39 |
-
# b = summarizer(first_sentences, min_length = 20, max_length = 120, do_sample = False)
|
40 |
-
# b = b[0]['summary_text'].replace(' .', '.').strip()
|
41 |
-
# return b
|
42 |
-
# Since no summarizer is defined, return the first sentences for now
|
43 |
return first_sentences
|
44 |
except Exception as e:
|
45 |
raise gr.Error(f"Exception: {e}")
|
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>")
|
@@ -54,10 +49,7 @@ with gr.Blocks() as demo:
|
|
54 |
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
|
55 |
result_button_transcribe = gr.Button('1. Transcribe')
|
56 |
output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
|
57 |
-
#result_button_summary = gr.Button('2. Create Summary')
|
58 |
-
#output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
|
59 |
|
60 |
-
result_button_transcribe.click(get_text, inputs
|
61 |
-
#result_button_summary.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)
|
62 |
|
63 |
-
demo.queue(default_enabled
|
|
|
11 |
ydl_opts = {
|
12 |
'format': 'bestaudio/best',
|
13 |
'noplaylist': True,
|
14 |
+
'quiet': True,
|
15 |
+
'outtmpl': '%(title)s.%(ext)s' # Specify output template to get the file path
|
16 |
}
|
17 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
18 |
info = ydl.extract_info(url, download=True)
|
19 |
+
# Use 'requested_downloads' to get the downloaded file path
|
20 |
+
audio_file = ydl.prepare_filename(info)
|
21 |
return audio_file
|
22 |
except Exception as e:
|
23 |
raise gr.Error(f"Exception: {e}")
|
|
|
36 |
def get_summary(article):
|
37 |
try:
|
38 |
first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
|
|
|
|
|
|
|
|
|
|
|
39 |
return first_sentences
|
40 |
except Exception as e:
|
41 |
raise gr.Error(f"Exception: {e}")
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
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>")
|
|
|
45 |
gr.Markdown("<center>Enter the link of any YouTube video to generate a text transcript of the video.</center>")
|
46 |
gr.Markdown("<center><b>'Whisper is a neural net that approaches human level robustness and accuracy on English speech recognition.'</b></center>")
|
47 |
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>")
|
|
|
49 |
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
|
50 |
result_button_transcribe = gr.Button('1. Transcribe')
|
51 |
output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
|
|
|
|
|
52 |
|
53 |
+
result_button_transcribe.click(get_text, inputs=input_text_url, outputs=output_text_transcribe)
|
|
|
54 |
|
55 |
+
demo.queue(default_enabled=True).launch(debug=True)
|