TheKnight115 commited on
Commit
4de3665
·
verified ·
1 Parent(s): 37663c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -128,15 +128,6 @@ def process_video_and_save(uploaded_file):
128
  out.write(frame_bgr)
129
 
130
  out.release()
131
-
132
- # Create a download button for the processed video
133
- with open(output_path, "rb") as video_file:
134
- btn = st.download_button(
135
- label="Download Processed Video",
136
- data=video_file,
137
- file_name="processed_video.mp4",
138
- mime="video/mp4"
139
- )
140
 
141
  return output_path
142
 
@@ -146,20 +137,24 @@ def process_video_and_save(uploaded_file):
146
  def live_video_feed():
147
  stframe = st.empty()
148
  video = cv2.VideoCapture(0)
149
- start_time = time.time()
 
 
 
150
 
151
  while True:
152
  ret, frame = video.read()
153
  if not ret:
 
154
  break
155
 
 
156
  results = run_yolo(frame)
157
- processed_frame = process_results(results, frame)
158
- processed_frame_rgb = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
159
- stframe.image(processed_frame_rgb, channels="RGB", use_column_width=True)
160
 
161
- elapsed_time = time.time() - start_time
162
- st.write(f"Elapsed Time: {elapsed_time:.2f} seconds")
163
 
164
  if st.button("Stop"):
165
  break
@@ -231,7 +226,15 @@ def main():
231
  uploaded_file = st.file_uploader("Choose a video...", type=["mp4", "mov"])
232
  if uploaded_file is not None:
233
  output_path = process_video_and_save(uploaded_file)
234
- st.video(output_path)
 
 
 
 
 
 
 
 
235
 
236
  elif input_type == "Live Feed":
237
  live_video_feed()
 
128
  out.write(frame_bgr)
129
 
130
  out.release()
 
 
 
 
 
 
 
 
 
131
 
132
  return output_path
133
 
 
137
  def live_video_feed():
138
  stframe = st.empty()
139
  video = cv2.VideoCapture(0)
140
+
141
+ if not video.isOpened():
142
+ st.error("Unable to access the webcam.")
143
+ return
144
 
145
  while True:
146
  ret, frame = video.read()
147
  if not ret:
148
+ st.error("Failed to capture frame.")
149
  break
150
 
151
+ # Run YOLO on the captured frame
152
  results = run_yolo(frame)
153
+ annotated_frame = process_results(results, frame)
154
+ annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
 
155
 
156
+ # Display the frame with detections
157
+ stframe.image(annotated_frame_rgb, channels="RGB", use_column_width=True)
158
 
159
  if st.button("Stop"):
160
  break
 
226
  uploaded_file = st.file_uploader("Choose a video...", type=["mp4", "mov"])
227
  if uploaded_file is not None:
228
  output_path = process_video_and_save(uploaded_file)
229
+
230
+ # Now, move the download button here, outside the cached function
231
+ with open(output_path, "rb") as video_file:
232
+ btn = st.download_button(
233
+ label="Download Processed Video",
234
+ data=video_file,
235
+ file_name="processed_video.mp4",
236
+ mime="video/mp4"
237
+ )
238
 
239
  elif input_type == "Live Feed":
240
  live_video_feed()