rajesh1729 commited on
Commit
28b5116
1 Parent(s): 62d8640

Create new file

Browse files
Files changed (1) hide show
  1. app.py +45 -0
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
+
6
+ model = whisper.load_model("base")
7
+ summarizer = pipeline("summarization")
8
+
9
+ def get_audio(url):
10
+ yt = YouTube(url)
11
+ video = yt.streams.filter(only_audio=True).first()
12
+ out_file=video.download(output_path=".")
13
+ base, ext = os.path.splitext(out_file)
14
+ new_file = base+'.mp3'
15
+ os.rename(out_file, new_file)
16
+ a = new_file
17
+ return a
18
+
19
+ def get_text(url):
20
+ result = model.transcribe(get_audio(url))
21
+ return result['text']
22
+
23
+ def get_summary(url):
24
+ article = get_text(url)
25
+ b = summarizer(article)
26
+ b = b[0]['summary_text']
27
+ return b
28
+
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("<h1><center>Youtube video transcription with OpenAI's Whisper</center></h1>")
31
+ gr.Markdown("<center>Enter the link of any youtube video to get the transcription of the video and a summary of the video in the form of text.</center>")
32
+ with gr.Tab('Get the transcription of any Youtube video'):
33
+ with gr.Row():
34
+ input_text_1 = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
35
+ output_text_1 = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
36
+ result_button_1 = gr.Button('Get Transcription')
37
+ with gr.Tab('Summary of Youtube video'):
38
+ with gr.Row():
39
+ input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
40
+ output_text = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
41
+ result_button = gr.Button('Get Summary')
42
+
43
+ result_button.click(get_summary, inputs = input_text, outputs = output_text)
44
+ result_button_1.click(get_text, inputs = input_text_1, outputs = output_text_1)
45
+ demo.launch()