Omkar1872 commited on
Commit
7eb88b9
Β·
verified Β·
1 Parent(s): 5d1b14c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -50
app.py CHANGED
@@ -1,70 +1,54 @@
1
  import streamlit as st
2
- import tempfile
3
  import os
4
- import yt_dlp
5
  from utils.transcriber import transcribe_audio
6
  from utils.summarizer import summarize_text
 
 
7
 
8
- # Title
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
- # Video input
20
- st.subheader("πŸ“₯ Upload or Link a Video")
21
- video_source = st.radio("Choose input method:", ["YouTube Link", "Upload File"])
22
 
23
  video_path = None
24
 
25
- if video_source == "YouTube Link":
26
  yt_url = st.text_input("Enter YouTube URL:")
27
- if yt_url:
28
- with st.spinner("Downloading video..."):
29
- try:
30
- tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
31
  ydl_opts = {
32
- "outtmpl": tmp_file.name,
33
- "format": "mp4",
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
- st.success("YouTube video downloaded!")
40
- except Exception as e:
41
- st.error(f"Error downloading video: {e}")
42
 
43
- elif video_source == "Upload File":
44
- uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "mov", "avi", "mkv"])
45
- if uploaded_file:
46
- tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
47
- tmp_file.write(uploaded_file.read())
48
- tmp_file.close()
49
- video_path = tmp_file.name
50
- st.success("File uploaded successfully!")
51
 
52
- # Process
53
- if video_path and st.button("πŸš€ Process Video"):
54
- with st.spinner("Transcribing video..."):
55
- try:
56
- transcript = transcribe_audio(video_path)
57
- st.subheader("πŸ“ Transcript")
58
- st.text_area("", transcript, height=200)
59
 
60
- with st.spinner("Summarizing..."):
61
- summary = summarize_text(transcript)
62
- st.subheader("✨ Summary")
63
- st.write(summary)
64
 
65
- except Exception as e:
66
- st.error(f"Processing failed: {e}")
 
 
 
67
 
68
- # Footer
69
- st.markdown("---")
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}")