JaganathC commited on
Commit
5d9508a
Β·
verified Β·
1 Parent(s): 87ecfda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
app.py CHANGED
@@ -6,9 +6,33 @@ import whisper
6
  from transformers import pipeline, MarianMTModel, MarianTokenizer
7
  import yt_dlp as youtube_dl
8
 
9
-
10
  # App Configuration
11
- st.set_page_config(page_title="Video-to-Text Summarization", layout="centered")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Header
14
  st.title("πŸŽ₯ Smart Video-to-Text Summarization App")
@@ -23,24 +47,23 @@ This app helps you:
23
  if "video_path" not in st.session_state:
24
  st.session_state.video_path = None
25
 
26
- # 1. Upload Video Section
27
  st.header("Upload Your Video")
28
 
29
- # Choose upload option
30
- upload_option = st.selectbox("Select Upload Method", ["Local", "YouTube URL"])
31
 
32
- # Upload Local File
33
- if upload_option == "Local":
34
- video_file = st.file_uploader("Upload your video file", type=["mp4", "mkv", "avi"])
35
  if video_file:
36
  with open("uploaded_video.mp4", "wb") as f:
37
  f.write(video_file.read())
38
  st.session_state.video_path = "uploaded_video.mp4"
39
  st.success("Video uploaded successfully!")
40
 
41
- # Download Video from YouTube
42
- elif upload_option == "YouTube URL":
43
- youtube_url = st.text_input("Enter YouTube URL")
44
  if youtube_url:
45
  try:
46
  os.system(f"yt-dlp -o video.mp4 {youtube_url}")
@@ -49,12 +72,11 @@ elif upload_option == "YouTube URL":
49
  except Exception as e:
50
  st.error(f"Error downloading video: {str(e)}")
51
 
52
- # 2. Process Video Section (After Upload)
53
  if st.session_state.video_path:
54
  st.header("Process Your Video")
55
  st.write(f"Processing {st.session_state.video_path}...")
56
-
57
- # Extract Audio from Video
58
  def extract_audio(video_path):
59
  try:
60
  audio = AudioSegment.from_file(video_path)
@@ -66,8 +88,7 @@ if st.session_state.video_path:
66
  return None
67
 
68
  audio_path = extract_audio(st.session_state.video_path)
69
-
70
- # Real-time Audio Transcription
71
  def transcribe_audio(audio_path):
72
  try:
73
  model = whisper.load_model("base")
@@ -81,11 +102,10 @@ if st.session_state.video_path:
81
  if audio_path:
82
  transcription = transcribe_audio(audio_path)
83
 
84
- # 3. Summarize and Translate
85
  if 'transcription' in locals():
86
  st.header("Results")
87
 
88
- # Summarize Text
89
  def summarize_text(text):
90
  try:
91
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
@@ -98,7 +118,6 @@ if 'transcription' in locals():
98
 
99
  summary = summarize_text(transcription)
100
 
101
- # Translate Text
102
  def translate_text(text, src_lang="en", tgt_lang="es"):
103
  try:
104
  model_name = f"Helsinki-NLP/opus-mt-{src_lang}-{tgt_lang}"
@@ -117,4 +136,4 @@ if 'transcription' in locals():
117
  translated_summary = translate_text(summary, tgt_lang=target_language)
118
 
119
  else:
120
- st.info("Please upload a video to start the process.")
 
6
  from transformers import pipeline, MarianMTModel, MarianTokenizer
7
  import yt_dlp as youtube_dl
8
 
 
9
  # App Configuration
10
+ st.set_page_config(page_title="Video-to-Text Summarization", layout="wide")
11
+
12
+ # Navbar-like Section
13
+ st.markdown("""
14
+ <style>
15
+ .nav-links {
16
+ display: flex;
17
+ justify-content: center;
18
+ gap: 20px;
19
+ }
20
+ .nav-links a {
21
+ text-decoration: none;
22
+ padding: 10px 20px;
23
+ background: #4CAF50;
24
+ color: white;
25
+ border-radius: 5px;
26
+ }
27
+ </style>
28
+ """, unsafe_allow_html=True)
29
+
30
+ st.markdown("""
31
+ <div class='nav-links'>
32
+ <a href='#local-upload'>Upload Local Video</a>
33
+ <a href='#youtube-upload'>Upload YouTube Video</a>
34
+ </div>
35
+ """, unsafe_allow_html=True)
36
 
37
  # Header
38
  st.title("πŸŽ₯ Smart Video-to-Text Summarization App")
 
47
  if "video_path" not in st.session_state:
48
  st.session_state.video_path = None
49
 
50
+ # Upload Video Section
51
  st.header("Upload Your Video")
52
 
53
+ col1, col2 = st.columns(2)
 
54
 
55
+ with col1:
56
+ st.subheader("πŸ“ Upload Local Video")
57
+ video_file = st.file_uploader("Upload your video file", type=["mp4", "mkv", "avi"], key="local-upload")
58
  if video_file:
59
  with open("uploaded_video.mp4", "wb") as f:
60
  f.write(video_file.read())
61
  st.session_state.video_path = "uploaded_video.mp4"
62
  st.success("Video uploaded successfully!")
63
 
64
+ with col2:
65
+ st.subheader("πŸ“Ί Upload YouTube Video")
66
+ youtube_url = st.text_input("Enter YouTube URL", key="youtube-upload")
67
  if youtube_url:
68
  try:
69
  os.system(f"yt-dlp -o video.mp4 {youtube_url}")
 
72
  except Exception as e:
73
  st.error(f"Error downloading video: {str(e)}")
74
 
75
+ # Process Video Section
76
  if st.session_state.video_path:
77
  st.header("Process Your Video")
78
  st.write(f"Processing {st.session_state.video_path}...")
79
+
 
80
  def extract_audio(video_path):
81
  try:
82
  audio = AudioSegment.from_file(video_path)
 
88
  return None
89
 
90
  audio_path = extract_audio(st.session_state.video_path)
91
+
 
92
  def transcribe_audio(audio_path):
93
  try:
94
  model = whisper.load_model("base")
 
102
  if audio_path:
103
  transcription = transcribe_audio(audio_path)
104
 
105
+ # Summarize and Translate Section
106
  if 'transcription' in locals():
107
  st.header("Results")
108
 
 
109
  def summarize_text(text):
110
  try:
111
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
118
 
119
  summary = summarize_text(transcription)
120
 
 
121
  def translate_text(text, src_lang="en", tgt_lang="es"):
122
  try:
123
  model_name = f"Helsinki-NLP/opus-mt-{src_lang}-{tgt_lang}"
 
136
  translated_summary = translate_text(summary, tgt_lang=target_language)
137
 
138
  else:
139
+ st.info("Please upload a video to start the process.")