Spaces:
Sleeping
Sleeping
eaglelandsonce
commited on
Commit
•
87359bb
1
Parent(s):
69bf66b
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,46 @@
|
|
|
|
1 |
from pytube import YouTube
|
2 |
from transformers import pipeline
|
3 |
-
import
|
4 |
import os
|
5 |
|
6 |
model = whisper.load_model("base")
|
7 |
summarizer = pipeline("summarization")
|
8 |
|
9 |
-
def get_audio_from_video(file_path):
|
10 |
-
# You can use a library like moviepy or ffmpeg to extract audio from the video
|
11 |
-
# For simplicity, I'm assuming the video is already in a format that the model can transcribe
|
12 |
-
return file_path
|
13 |
-
|
14 |
def get_audio(url):
|
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 |
-
st.text_area('Summary text of the Youtube Video', summary)
|
52 |
-
|
53 |
-
elif option == 'Upload a video file':
|
54 |
-
uploaded_file = st.file_uploader("Choose a video file", type=["mp4"])
|
55 |
-
if uploaded_file:
|
56 |
-
video_path = "temp_video_file.mp4"
|
57 |
-
with open(video_path, "wb") as f:
|
58 |
-
f.write(uploaded_file.getvalue())
|
59 |
-
if st.button('Transcribe Uploaded Video'):
|
60 |
-
transcription = get_text(file_path=video_path)
|
61 |
-
st.text_area('Transcription of the uploaded video file', transcription)
|
|
|
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(url):
|
25 |
+
article = get_text(url)
|
26 |
+
b = summarizer(article)
|
27 |
+
b = b[0]['summary_text']
|
28 |
+
return b
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("<h1><center>Youtube video transcription with OpenAI's Whisper</center></h1>")
|
32 |
+
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>")
|
33 |
+
with gr.Tab('Get the transcription of any Youtube video'):
|
34 |
+
with gr.Row():
|
35 |
+
input_text_1 = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
|
36 |
+
output_text_1 = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
|
37 |
+
result_button_1 = gr.Button('Get Transcription')
|
38 |
+
with gr.Tab('Summary of Youtube video'):
|
39 |
+
with gr.Row():
|
40 |
+
input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
|
41 |
+
output_text = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
|
42 |
+
result_button = gr.Button('Get Summary')
|
43 |
+
|
44 |
+
result_button.click(get_summary, inputs = input_text, outputs = output_text)
|
45 |
+
result_button_1.click(get_text, inputs = input_text_1, outputs = output_text_1)
|
46 |
+
demo.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|