Commit
·
bc736f8
1
Parent(s):
a2ebd0d
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import whisper
|
| 2 |
+
from pytube import YouTube
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
model = whisper.load_model("base")
|
| 8 |
+
summarizer = pipeline("summarization")
|
| 9 |
+
|
| 10 |
+
def get_audio(url):
|
| 11 |
+
yt = YouTube(url)
|
| 12 |
+
video = yt.streams.filter(only_audio=True).first()
|
| 13 |
+
out_file=video.download(output_path=".")
|
| 14 |
+
base, ext = os.path.splitext(out_file)
|
| 15 |
+
new_file = base+'.mp3'
|
| 16 |
+
os.rename(out_file, new_file)
|
| 17 |
+
a = new_file
|
| 18 |
+
return a
|
| 19 |
+
|
| 20 |
+
def get_text(url):
|
| 21 |
+
result = model.transcribe(get_audio(url))
|
| 22 |
+
return result['text']
|
| 23 |
+
|
| 24 |
+
def get_summary(article):
|
| 25 |
+
print(article)
|
| 26 |
+
b = summarizer(article, min_length=5, max_length=20)
|
| 27 |
+
print(b)
|
| 28 |
+
#b = b[0]['summary_text']
|
| 29 |
+
return b
|
| 30 |
+
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("<h1><center>Free YouTube URL Video to Text using OpenAI's Whisper Model</center></h1>")
|
| 33 |
+
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>")
|
| 34 |
+
|
| 35 |
+
input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
|
| 36 |
+
result_button_transcribe = gr.Button('1. Transcribe')
|
| 37 |
+
output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
|
| 38 |
+
|
| 39 |
+
result_button = gr.Button('2. Create Summary')
|
| 40 |
+
output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
|
| 41 |
+
|
| 42 |
+
result_button_1.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
|
| 43 |
+
result_button.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)
|
| 44 |
+
|
| 45 |
+
demo.launch(debug = True)
|