Spaces:
Sleeping
Sleeping
first commit
Browse files
app.py
CHANGED
@@ -1,71 +1,45 @@
|
|
1 |
import streamlit as st
|
2 |
from pytube import YouTube
|
3 |
from moviepy.editor import *
|
4 |
-
import
|
5 |
-
from transformers import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
predicted_ids = torch.argmax(logits, dim=-1)
|
47 |
-
|
48 |
-
# Decode the speech
|
49 |
-
transcription = tokenizer.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
50 |
-
|
51 |
-
# Ensure transcription is a string, not empty, and not too short
|
52 |
-
if isinstance(transcription, str) and transcription.strip() and len(transcription) > 50:
|
53 |
-
# Show progress
|
54 |
-
st.progress(75)
|
55 |
-
|
56 |
-
# Initialize the summarizer
|
57 |
-
summarizer = pipeline("summarization")
|
58 |
-
|
59 |
-
# Summarization
|
60 |
-
summary = summarizer(transcription, max_length=130, min_length=30, do_sample=False)
|
61 |
-
st.success("Done!")
|
62 |
-
st.write("### Summary:")
|
63 |
-
st.write(summary[0]['summary_text'])
|
64 |
-
|
65 |
-
# Final progress
|
66 |
-
st.progress(100)
|
67 |
-
else:
|
68 |
-
st.error("Transcription result is empty, too short, or not a string.")
|
69 |
-
|
70 |
-
except Exception as e:
|
71 |
-
st.error(f"An error occurred: {e}")
|
|
|
1 |
import streamlit as st
|
2 |
from pytube import YouTube
|
3 |
from moviepy.editor import *
|
4 |
+
import speech_recognition as sr
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
def download_and_extract_audio(youtube_link):
|
8 |
+
yt = YouTube(youtube_link)
|
9 |
+
video = yt.streams.filter(only_audio=True).first()
|
10 |
+
out_file = video.download(output_path=".")
|
11 |
+
base, ext = os.path.splitext(out_file)
|
12 |
+
new_file = base + '.mp3'
|
13 |
+
os.rename(out_file, new_file)
|
14 |
+
return new_file
|
15 |
+
|
16 |
+
def transcribe_audio(audio_path):
|
17 |
+
recognizer = sr.Recognizer()
|
18 |
+
with sr.AudioFile(audio_path) as source:
|
19 |
+
audio_data = recognizer.record(source)
|
20 |
+
text = recognizer.recognize_google(audio_data)
|
21 |
+
return text
|
22 |
+
|
23 |
+
def summarize_text(text):
|
24 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
25 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
26 |
+
return summary[0]['summary_text']
|
27 |
+
|
28 |
+
def main():
|
29 |
+
st.title("YouTube Video Summary")
|
30 |
+
youtube_link = st.text_input("Enter YouTube Video Link:")
|
31 |
+
if st.button("Summarize"):
|
32 |
+
with st.spinner('Downloading and extracting audio...'):
|
33 |
+
audio_path = download_and_extract_audio(youtube_link)
|
34 |
+
with st.spinner('Transcribing audio to text...'):
|
35 |
+
transcription = transcribe_audio(audio_path)
|
36 |
+
with st.spinner('Summarizing transcription...'):
|
37 |
+
summary = summarize_text(transcription)
|
38 |
+
|
39 |
+
st.subheader("Transcription:")
|
40 |
+
st.write(transcription)
|
41 |
+
st.subheader("Summary:")
|
42 |
+
st.write(summary)
|
43 |
+
|
44 |
+
if __name__ == '__main__':
|
45 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|