File size: 1,244 Bytes
69f635d 2fb9bf2 69f635d 2fb9bf2 69f635d 2fb9bf2 69f635d 2fb9bf2 |
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 |
import whisper
from transformers import pipeline
import ffmpeg
import os
import streamlit as st
import torch
# Step 1: File Upload in Streamlit
uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "mkv", "avi", "mov"])
if uploaded_file is not None:
# Save the uploaded video file
video_path = "uploaded_video.mp4"
with open(video_path, "wb") as f:
f.write(uploaded_file.getbuffer())
# Step 2: Process the Video
# Load Whisper Model for Transcription
whisper_model = whisper.load_model("base")
# Extract audio from video using ffmpeg
audio_path = "audio.wav"
ffmpeg.input(video_path).output(audio_path).run(overwrite_output=True)
# Transcribe Audio
transcription = whisper_model.transcribe(audio_path)["text"]
st.write("Transcription:\n", transcription)
# Summarize Transcription using Hugging Face Transformers
summarizer = pipeline("summarization", model="facebook/bart-large-cnn", device=0 if torch.cuda.is_available() else -1)
summary = summarizer(transcription, max_length=150, min_length=30, do_sample=False)[0]["summary_text"]
st.write("\nSummary:\n", summary)
# Cleanup
os.remove(audio_path)
os.remove(video_path)
|