Spaces:
Sleeping
Sleeping
File size: 1,801 Bytes
52930d0 ce3a3a9 ee8c3b8 5de25ba ee8c3b8 5de25ba ee8c3b8 |
1 2 3 4 5 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 47 48 49 50 51 52 53 |
import streamlit as st
from pytube import YouTube
from moviepy.editor import *
import speech_recognition as sr
from transformers import pipeline
from pydub import AudioSegment
import os
def download_and_extract_audio(youtube_link):
yt = YouTube(youtube_link)
video = yt.streams.filter(only_audio=True).first()
out_file = video.download(output_path=".")
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
# Convert MP3 to WAV for compatibility with speech_recognition
audio = AudioSegment.from_mp3(new_file)
wav_file = base + '.wav'
audio.export(wav_file, format="wav")
return wav_file
def transcribe_audio(audio_path):
recognizer = sr.Recognizer()
with sr.AudioFile(audio_path) as source:
audio_data = recognizer.record(source)
text = recognizer.recognize_google(audio_data)
return text
def summarize_text(text):
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
return summary[0]['summary_text']
def main():
st.title("YouTube Video Summary")
youtube_link = st.text_input("Enter YouTube Video Link:")
if st.button("Summarize"):
with st.spinner('Downloading and extracting audio...'):
audio_path = download_and_extract_audio(youtube_link)
with st.spinner('Transcribing audio to text...'):
transcription = transcribe_audio(audio_path)
with st.spinner('Summarizing transcription...'):
summary = summarize_text(transcription)
st.subheader("Transcription:")
st.write(transcription)
st.subheader("Summary:")
st.write(summary)
if __name__ == '__main__':
main()
|