File size: 1,591 Bytes
bc736f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import whisper
from pytube import YouTube
from transformers import pipeline
import gradio as gr
import os

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

def get_audio(url):
  yt = YouTube(url)
  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

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

def get_summary(article):
  print(article)
  b = summarizer(article, min_length=5, max_length=20)
  print(b)
  #b = b[0]['summary_text']
  return b
  
with gr.Blocks() as demo:
  gr.Markdown("<h1><center>Free YouTube URL Video to Text using OpenAI's Whisper 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>")

  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 = gr.Button('2. Create Summary')
  output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')

  result_button_1.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
  result_button.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)

demo.launch(debug = True)