Javed7 commited on
Commit
68bbd23
·
1 Parent(s): eae6dc9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ from pytube import YouTube
3
+ from transformers import pipeline
4
+ import gradio as gr
5
+ import os
6
+
7
+ model_options = ["tiny", "base", "small", "medium", "large"]
8
+ selected_model = gr.Dropdown(options=model_options, label="Select Model")
9
+
10
+ def set_model(model_name):
11
+ global model
12
+ model = whisper.load_model(model_name)
13
+
14
+ summarizer = pipeline("summarization")
15
+
16
+ def get_audio(url):
17
+ yt = YouTube(url)
18
+ video = yt.streams.filter(only_audio=True).first()
19
+ out_file=video.download(output_path=".")
20
+ base, ext = os.path.splitext(out_file)
21
+ new_file = base+'.mp3'
22
+ os.rename(out_file, new_file)
23
+ a = new_file
24
+ return a
25
+
26
+ def get_text(url):
27
+ result = model.transcribe(get_audio(url))
28
+ return result['text']
29
+
30
+ def get_summary(url):
31
+ article = get_text(url)
32
+ b = summarizer(article)
33
+ b = b[0]['summary_text']
34
+ return b
35
+
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("<h1><center>Youtube video transcription with OpenAI's Whisper</center></h1>")
38
+ 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>")
39
+ with gr.Tab('Get the transcription of any Youtube video'):
40
+ selected_model.onchange(set_model)
41
+ with gr.Row():
42
+ input_text_1 = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
43
+ output_text_1 = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
44
+ result_button_1 = gr.Button('Get Transcription')
45
+ with gr.Tab('Summary of Youtube video'):
46
+ with gr.Row():
47
+ input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
48
+ output_text = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
49
+ result_button = gr.Button('Get Summary')
50
+
51
+ result_button.click(get_summary, inputs = input_text, outputs = output_text)
52
+ result_button_1.click(get_text, inputs = input_text_1, outputs = output_text_1)
53
+ demo.launch(debug=True)