eaglelandsonce commited on
Commit
69bf66b
1 Parent(s): 938596d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pytube import YouTube
2
+ from transformers import pipeline
3
+ import streamlit as st
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
+ yt = YouTube(url)
16
+ video = yt.streams.filter(only_audio=True).first()
17
+ out_file = video.download(output_path=".")
18
+ base, ext = os.path.splitext(out_file)
19
+ new_file = base + '.mp3'
20
+ os.rename(out_file, new_file)
21
+ return new_file
22
+
23
+ def get_text(url=None, file_path=None):
24
+ if url:
25
+ result = model.transcribe(get_audio(url))
26
+ elif file_path:
27
+ result = model.transcribe(get_audio_from_video(file_path))
28
+ return result['text']
29
+
30
+ def get_summary(url=None, file_path=None):
31
+ article = get_text(url, file_path)
32
+ b = summarizer(article)
33
+ b = b[0]['summary_text']
34
+ return b
35
+
36
+ st.title("Youtube video transcription with OpenAI's Whisper")
37
+ st.write("Enter the link of any youtube video or upload a video file to get the transcription and a summary in the form of text.")
38
+
39
+ option = st.radio('Choose an option', ['Get the transcription of any Youtube video', 'Summary of Youtube video', 'Upload a video file'])
40
+
41
+ if option == 'Get the transcription of any Youtube video':
42
+ url1 = st.text_input('Enter the Youtube video URL')
43
+ if st.button('Get Transcription'):
44
+ transcription = get_text(url1)
45
+ st.text_area('Transcription of the video', transcription)
46
+
47
+ elif option == 'Summary of Youtube video':
48
+ url2 = st.text_input('Enter the Youtube video URL')
49
+ if st.button('Get Summary'):
50
+ summary = get_summary(url2)
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)