File size: 2,591 Bytes
bc736f8
 
 
 
 
b640e62
bc736f8
 
 
 
 
 
b513c56
129b6dc
 
 
 
 
 
 
 
b513c56
129b6dc
bc736f8
 
c5541dd
bc736f8
959cf33
bc736f8
 
b640e62
69ba241
e36067e
69ba241
bc736f8
 
 
5bdd729
bc736f8
c353027
8553442
bc736f8
 
 
 
 
713e0a1
bc736f8
 
c5541dd
 
bc736f8
dcd462d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import whisper
from pytube import YouTube
from transformers import pipeline
import gradio as gr
import os
import re

model = whisper.load_model("base")
summarizer = pipeline("summarization")

def get_audio(url):
  yt = YouTube(url)
  if yt.length < 5400:
    video = yt.streams.filter(only_audio=True).first()
    out_file=video.download(output_path=".")
    base, ext = os.path.splitext(out_file)
    new_file = base+'.mp3'
    os.rename(out_file, new_file)
    a = new_file
    return a
  else:
    raise gr.Error("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.")
    return ""

def get_text(url):
  if url != '' : output_text_transcribe = ''
  result = model.transcribe(get_audio(url))
  return result['text'].strip()

def get_summary(article):
  first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
  b = summarizer(first_sentences, min_length = 20, max_length = 120, do_sample = False)
  b = b[0]['summary_text'].replace(' .', '.').strip()
  
  return b
  
with gr.Blocks() as demo:
  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>")
  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>")
  gr.Markdown("<center><b>'Whisper is a neural net that approaches human level robustness and accuracy on English speech recognition.'</b></center>")
  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>")

  input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
  result_button_transcribe = gr.Button('1. Transcribe')
  output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')

  result_button_summary = gr.Button('2. Create Summary')
  output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')

  result_button_transcribe.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
  result_button_summary.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)

demo.queue(default_enabled=False).launch(debug = True)