stevafernandes commited on
Commit
c829dbb
·
verified ·
1 Parent(s): ee0a228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -20
app.py CHANGED
@@ -26,10 +26,13 @@ class VideoProcessor:
26
  except Exception as e:
27
  raise RuntimeError(f"Failed to upload video: {str(e)}")
28
 
29
- def wait_for_processing(self, video_file):
30
  max_attempts = 60 # Maximum wait time: 2 minutes
31
  attempts = 0
32
  while video_file.state.name == "PROCESSING" and attempts < max_attempts:
 
 
 
33
  time.sleep(2)
34
  video_file = genai.get_file(video_file.name)
35
  attempts += 1
@@ -56,6 +59,41 @@ if "video_file" not in st.session_state:
56
  if "video_name" not in st.session_state:
57
  st.session_state.video_name = None
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  # Main app function
60
  def main():
61
  st.set_page_config(page_title="Video Retrieval-Augmented Generation", layout="wide")
@@ -104,25 +142,32 @@ def main():
104
  tmp.write(uploaded_file.getvalue())
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
-
112
- video_file = st.session_state.video_processor.upload_video(tmp_path, uploaded_file.name)
113
- progress_bar.progress(50, text="Processing video...")
114
-
115
- processed_file = st.session_state.video_processor.wait_for_processing(video_file)
116
- progress_bar.progress(100, text="Complete!")
117
-
118
- # Update session state
119
- st.session_state.video_file = processed_file
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)}")
 
26
  except Exception as e:
27
  raise RuntimeError(f"Failed to upload video: {str(e)}")
28
 
29
+ def wait_for_processing(self, video_file, status_placeholder):
30
  max_attempts = 60 # Maximum wait time: 2 minutes
31
  attempts = 0
32
  while video_file.state.name == "PROCESSING" and attempts < max_attempts:
33
+ # Update status text with dots animation
34
+ dots = "." * ((attempts % 3) + 1)
35
+ status_placeholder.markdown(f"**Processing video{dots}**")
36
  time.sleep(2)
37
  video_file = genai.get_file(video_file.name)
38
  attempts += 1
 
59
  if "video_name" not in st.session_state:
60
  st.session_state.video_name = None
61
 
62
+ # Buffering animation CSS
63
+ def show_buffering_animation():
64
+ st.markdown("""
65
+ <style>
66
+ .buffering-container {
67
+ display: flex;
68
+ flex-direction: column;
69
+ align-items: center;
70
+ justify-content: center;
71
+ padding: 20px;
72
+ }
73
+ .buffering-spinner {
74
+ width: 50px;
75
+ height: 50px;
76
+ border: 5px solid #f3f3f3;
77
+ border-top: 5px solid #3498db;
78
+ border-radius: 50%;
79
+ animation: spin 1s linear infinite;
80
+ }
81
+ @keyframes spin {
82
+ 0% { transform: rotate(0deg); }
83
+ 100% { transform: rotate(360deg); }
84
+ }
85
+ .buffering-text {
86
+ margin-top: 10px;
87
+ font-size: 16px;
88
+ color: #666;
89
+ }
90
+ </style>
91
+ <div class="buffering-container">
92
+ <div class="buffering-spinner"></div>
93
+ <div class="buffering-text">Processing video...</div>
94
+ </div>
95
+ """, unsafe_allow_html=True)
96
+
97
  # Main app function
98
  def main():
99
  st.set_page_config(page_title="Video Retrieval-Augmented Generation", layout="wide")
 
142
  tmp.write(uploaded_file.getvalue())
143
  tmp_path = tmp.name
144
 
145
+ # Show buffering animation container
146
+ buffering_container = st.empty()
147
+ status_text = st.empty()
148
+
149
+ with buffering_container.container():
150
+ show_buffering_animation()
151
+
152
+ # Upload video
153
+ status_text.markdown("**Uploading video...**")
154
+ video_file = st.session_state.video_processor.upload_video(tmp_path, uploaded_file.name)
155
+
156
+ # Process video with status updates
157
+ processed_file = st.session_state.video_processor.wait_for_processing(video_file, status_text)
158
+
159
+ # Clear buffering animation
160
+ buffering_container.empty()
161
+ status_text.empty()
162
+
163
+ # Update session state
164
+ st.session_state.video_file = processed_file
165
+ st.session_state.video_name = uploaded_file.name
166
+ st.session_state.messages = [] # Clear previous conversation
167
+
168
+ st.success("Video processed successfully!")
169
+ time.sleep(1) # Show success message briefly
170
+ st.rerun()
171
 
172
  except Exception as e:
173
  st.error(f"Error processing video: {str(e)}")