stevafernandes commited on
Commit
b8ca55f
Β·
verified Β·
1 Parent(s): 9cced1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -57,8 +57,8 @@ if "video_name" not in st.session_state:
57
 
58
  # Main app function
59
  def main():
60
- st.set_page_config(page_title="Video Retrieval-Augmented Generation", page_icon="🎬", layout="wide")
61
- st.header("🎬 Video Retrieval-Augmented Generation - Gemini 2.0")
62
  st.markdown("---")
63
 
64
  # Step 1: API Key input
@@ -82,13 +82,13 @@ def main():
82
  # Display file info
83
  col1, col2 = st.columns(2)
84
  with col1:
85
- st.info(f"πŸ“ File: {uploaded_file.name}")
86
  with col2:
87
- st.info(f"πŸ’Ύ Size: {file_size:.2f} MB")
88
 
89
  # Check file size limit (200MB for Gemini)
90
  if file_size > 200:
91
- st.error("❌ File too large! Maximum size is 200MB")
92
  st.stop()
93
 
94
  # Process new video if different from current
@@ -105,7 +105,7 @@ def main():
105
  tmp_path = tmp.name
106
 
107
  # Upload and process with progress indication
108
- with st.spinner("πŸ“€ Uploading and processing video..."):
109
  progress_bar = st.progress(0)
110
  progress_bar.progress(25, text="Uploading video...")
111
 
@@ -120,12 +120,12 @@ def main():
120
  st.session_state.video_name = uploaded_file.name
121
  st.session_state.messages = [] # Clear previous conversation
122
 
123
- st.success("βœ… Video processed successfully!")
124
  time.sleep(1) # Show success message briefly
125
  progress_bar.empty() # Clear progress bar
126
 
127
  except Exception as e:
128
- st.error(f"❌ Error processing video: {str(e)}")
129
  st.session_state.video_file = None
130
  st.session_state.video_name = None
131
 
@@ -137,17 +137,17 @@ def main():
137
  # Display video player
138
  st.video(uploaded_file.getvalue())
139
  else:
140
- st.error("❌ Please upload a valid video file")
141
 
142
  # Control buttons
143
  col1, col2 = st.columns(2)
144
  with col1:
145
- if st.button("πŸ”„ Reset Chat", disabled=not st.session_state.messages):
146
  st.session_state.messages = []
147
  st.rerun()
148
 
149
  with col2:
150
- if st.button("πŸ—‘οΈ Reset All", disabled=not st.session_state.video_file):
151
  for key in list(st.session_state.keys()):
152
  del st.session_state[key]
153
  st.rerun()
@@ -172,19 +172,19 @@ def main():
172
  # Generate and display assistant response
173
  with st.chat_message("assistant"):
174
  placeholder = st.empty()
175
- with st.spinner("πŸ€” Thinking..."):
176
  try:
177
  response = st.session_state.video_processor.chat_with_video(
178
  st.session_state.video_file,
179
  user_question
180
  )
181
  except Exception as e:
182
- response = f"❌ Error: {str(e)}"
183
 
184
  placeholder.markdown(response)
185
  st.session_state.messages.append({"role": "assistant", "content": response})
186
  else:
187
- st.info("πŸ“Ή Please upload a video in Step 2 to start chatting.")
188
 
189
  if __name__ == "__main__":
190
  main()
 
57
 
58
  # Main app function
59
  def main():
60
+ st.set_page_config(page_title="Video Retrieval-Augmented Generation", layout="wide")
61
+ st.header("Video Retrieval-Augmented Generation - Gemini 2.0")
62
  st.markdown("---")
63
 
64
  # Step 1: API Key input
 
82
  # Display file info
83
  col1, col2 = st.columns(2)
84
  with col1:
85
+ st.info(f"File: {uploaded_file.name}")
86
  with col2:
87
+ st.info(f"Size: {file_size:.2f} MB")
88
 
89
  # Check file size limit (200MB for Gemini)
90
  if file_size > 200:
91
+ st.error("File too large! Maximum size is 200MB")
92
  st.stop()
93
 
94
  # Process new video if different from current
 
105
  tmp_path = tmp.name
106
 
107
  # Upload and process with progress indication
108
+ with st.spinner("Uploading and processing video..."):
109
  progress_bar = st.progress(0)
110
  progress_bar.progress(25, text="Uploading video...")
111
 
 
120
  st.session_state.video_name = uploaded_file.name
121
  st.session_state.messages = [] # Clear previous conversation
122
 
123
+ st.success("Video processed successfully!")
124
  time.sleep(1) # Show success message briefly
125
  progress_bar.empty() # Clear progress bar
126
 
127
  except Exception as e:
128
+ st.error(f"Error processing video: {str(e)}")
129
  st.session_state.video_file = None
130
  st.session_state.video_name = None
131
 
 
137
  # Display video player
138
  st.video(uploaded_file.getvalue())
139
  else:
140
+ st.error("Please upload a valid video file")
141
 
142
  # Control buttons
143
  col1, col2 = st.columns(2)
144
  with col1:
145
+ if st.button("Reset Chat", disabled=not st.session_state.messages):
146
  st.session_state.messages = []
147
  st.rerun()
148
 
149
  with col2:
150
+ if st.button("Reset All", disabled=not st.session_state.video_file):
151
  for key in list(st.session_state.keys()):
152
  del st.session_state[key]
153
  st.rerun()
 
172
  # Generate and display assistant response
173
  with st.chat_message("assistant"):
174
  placeholder = st.empty()
175
+ with st.spinner("Thinking..."):
176
  try:
177
  response = st.session_state.video_processor.chat_with_video(
178
  st.session_state.video_file,
179
  user_question
180
  )
181
  except Exception as e:
182
+ response = f"Error: {str(e)}"
183
 
184
  placeholder.markdown(response)
185
  st.session_state.messages.append({"role": "assistant", "content": response})
186
  else:
187
+ st.info("Please upload a video in Step 2 to start chatting.")
188
 
189
  if __name__ == "__main__":
190
  main()