Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| import tempfile | |
| from utils.transcriber import transcribe_audio | |
| from utils.summarizer import summarize_text | |
| import yt_dlp | |
| import ffmpeg | |
| st.title("π₯ Video Summarizer (Local Models, No API Key Needed)") | |
| # Step 1: Select input type | |
| input_method = st.radio("π₯ Upload or Link a Video", ["YouTube Link", "Upload File"]) | |
| video_path = None | |
| if input_method == "YouTube Link": | |
| yt_url = st.text_input("Enter YouTube URL:") | |
| if st.button("Download & Process") and yt_url: | |
| try: | |
| with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp_file: | |
| ydl_opts = { | |
| 'format': 'best', | |
| 'outtmpl': tmp_file.name, | |
| } | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| ydl.download([yt_url]) | |
| video_path = tmp_file.name | |
| except Exception as e: | |
| st.error(f"Error downloading video: {e}") | |
| elif input_method == "Upload File": | |
| uploaded_file = st.file_uploader("Upload Video", type=["mp4", "mov", "avi", "mkv"]) | |
| if uploaded_file is not None: | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file: | |
| tmp_file.write(uploaded_file.read()) | |
| video_path = tmp_file.name | |
| # Step 2: Process video if available | |
| if video_path: | |
| try: | |
| st.info("Transcribing video... This may take a while.") | |
| transcript = transcribe_audio(video_path) | |
| st.subheader("π Transcript") | |
| st.write(transcript) | |
| st.info("Summarizing transcript...") | |
| summary = summarize_text(transcript) | |
| st.subheader("π Summary") | |
| st.write(summary) | |
| except Exception as e: | |
| st.error(f"Processing failed: {e}") | |