Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,54 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import tempfile
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
from utils.transcriber import transcribe_audio
|
| 6 |
from utils.summarizer import summarize_text
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
st.set_page_config(page_title="π¬ Video Summarizer", layout="centered")
|
| 10 |
-
st.title("π¬ LLM-Powered Video Summarizer")
|
| 11 |
-
|
| 12 |
-
# API key status
|
| 13 |
-
OPENAI_KEY = os.getenv("OPENAI_API_KEY")
|
| 14 |
-
if OPENAI_KEY:
|
| 15 |
-
st.success("β
Using OpenAI API mode")
|
| 16 |
-
else:
|
| 17 |
-
st.warning("β οΈ No API key found β using local models (slower, may be less accurate)")
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
st.
|
| 21 |
-
video_source = st.radio("Choose input method:", ["YouTube Link", "Upload File"])
|
| 22 |
|
| 23 |
video_path = None
|
| 24 |
|
| 25 |
-
if
|
| 26 |
yt_url = st.text_input("Enter YouTube URL:")
|
| 27 |
-
if yt_url:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
| 31 |
ydl_opts = {
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
"quiet": True,
|
| 35 |
}
|
| 36 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 37 |
ydl.download([yt_url])
|
| 38 |
video_path = tmp_file.name
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
st.error(f"Error downloading video: {e}")
|
| 42 |
|
| 43 |
-
elif
|
| 44 |
-
uploaded_file = st.file_uploader("Upload
|
| 45 |
-
if uploaded_file:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
video_path = tmp_file.name
|
| 50 |
-
st.success("File uploaded successfully!")
|
| 51 |
|
| 52 |
-
# Process
|
| 53 |
-
if video_path
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
st.subheader("π Transcript")
|
| 58 |
-
st.text_area("", transcript, height=200)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.subheader("β¨ Summary")
|
| 63 |
-
st.write(summary)
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
st.
|
| 70 |
-
st.caption("Built with β€οΈ using Streamlit, Whisper, and GPT")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import os
|
| 3 |
+
import tempfile
|
| 4 |
from utils.transcriber import transcribe_audio
|
| 5 |
from utils.summarizer import summarize_text
|
| 6 |
+
import yt_dlp
|
| 7 |
+
import ffmpeg
|
| 8 |
|
| 9 |
+
st.title("π₯ Video Summarizer (Local Models, No API Key Needed)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Step 1: Select input type
|
| 12 |
+
input_method = st.radio("π₯ Upload or Link a Video", ["YouTube Link", "Upload File"])
|
|
|
|
| 13 |
|
| 14 |
video_path = None
|
| 15 |
|
| 16 |
+
if input_method == "YouTube Link":
|
| 17 |
yt_url = st.text_input("Enter YouTube URL:")
|
| 18 |
+
if st.button("Download & Process") and yt_url:
|
| 19 |
+
try:
|
| 20 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp_file:
|
|
|
|
| 21 |
ydl_opts = {
|
| 22 |
+
'format': 'best',
|
| 23 |
+
'outtmpl': tmp_file.name,
|
|
|
|
| 24 |
}
|
| 25 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 26 |
ydl.download([yt_url])
|
| 27 |
video_path = tmp_file.name
|
| 28 |
+
except Exception as e:
|
| 29 |
+
st.error(f"Error downloading video: {e}")
|
|
|
|
| 30 |
|
| 31 |
+
elif input_method == "Upload File":
|
| 32 |
+
uploaded_file = st.file_uploader("Upload Video", type=["mp4", "mov", "avi", "mkv"])
|
| 33 |
+
if uploaded_file is not None:
|
| 34 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
|
| 35 |
+
tmp_file.write(uploaded_file.read())
|
| 36 |
+
video_path = tmp_file.name
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Step 2: Process video if available
|
| 39 |
+
if video_path:
|
| 40 |
+
try:
|
| 41 |
+
st.info("Transcribing video... This may take a while.")
|
| 42 |
+
transcript = transcribe_audio(video_path)
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
st.subheader("π Transcript")
|
| 45 |
+
st.write(transcript)
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
st.info("Summarizing transcript...")
|
| 48 |
+
summary = summarize_text(transcript)
|
| 49 |
+
|
| 50 |
+
st.subheader("π Summary")
|
| 51 |
+
st.write(summary)
|
| 52 |
|
| 53 |
+
except Exception as e:
|
| 54 |
+
st.error(f"Processing failed: {e}")
|
|
|