awacke1 commited on
Commit
9f7c23f
·
verified ·
1 Parent(s): c4e1a06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -30
app.py CHANGED
@@ -332,28 +332,28 @@ def update_gallery():
332
  st.markdown(get_download_link(file, "image/png", "Download Image"), unsafe_allow_html=True)
333
 
334
  def get_available_video_devices():
335
- video_devices = []
336
- # Try V4L2 explicitly, then fall back to default backend
337
- for i in range(10):
338
- cap = cv2.VideoCapture(i, cv2.CAP_V4L2)
339
- if not cap.isOpened():
340
- cap = cv2.VideoCapture(i) # Try default backend
341
- if cap.isOpened():
342
- video_devices.append(f"Camera {i}")
343
- logger.info(f"Detected camera at index {i}")
344
- cap.release()
345
- else:
346
- logger.debug(f"No camera detected at index {i}")
347
- if not video_devices:
348
- logger.warning("No cameras detected by OpenCV. Checking system devices...")
349
- # Fallback: Check /dev/video* existence (Linux-specific)
350
- video_nodes = glob.glob("/dev/video*")
351
- if video_nodes:
352
- video_devices = [f"Camera {i}" for i in range(len(video_nodes))]
353
- logger.info(f"Found video nodes: {video_devices}")
354
  else:
355
- video_devices = ["Camera 0", "Camera 1"] # Default fallback for UI
356
- logger.warning("No /dev/video* nodes found; using default Camera 0 and 1")
 
357
  return video_devices
358
 
359
  def mock_search(query: str) -> str:
@@ -552,19 +552,15 @@ with tab2:
552
  st.header("Camera Snap 📷 (Dual Capture!)")
553
  video_devices = get_available_video_devices()
554
  st.subheader("Camera Settings ⚙️")
555
- if not any("Camera" in dev for dev in video_devices):
556
- st.warning("No video devices detected by OpenCV! 📷 Browser capture still active. Check logs and permissions (e.g., 'sudo usermod -aG video $USER').")
557
- else:
558
- st.write(f"Detected Video Devices: {', '.join(video_devices)}")
559
-
560
  # Camera selection with defaults
561
- default_cam0_index = 0 if video_devices else 0 # Default to Camera 0 or first fallback
562
- default_cam1_index = 1 if len(video_devices) > 1 else 0 # Default to Camera 1 or same as Cam 0
563
  selected_cam0 = st.selectbox("Select Camera 0", video_devices, index=default_cam0_index, key="cam0_select")
564
  selected_cam1 = st.selectbox("Select Camera 1", video_devices, index=default_cam1_index, key="cam1_select")
565
 
566
- st.info("Note: Camera selection is informational. Actual device used depends on browser settings. Configure in browser (e.g., Chrome > Settings > Privacy > Camera).")
567
-
568
  slice_count = st.number_input("Image Slice Count 🎞️", min_value=1, max_value=20, value=10, help="How many snaps to dream of? (Automation’s on vacation! 😜)")
569
  video_length = st.number_input("Video Dream Length (seconds) 🎥", min_value=1, max_value=30, value=10, help="Imagine a vid this long—sadly, we’re stuck with pics for now! 😂")
570
 
 
332
  st.markdown(get_download_link(file, "image/png", "Download Image"), unsafe_allow_html=True)
333
 
334
  def get_available_video_devices():
335
+ # Placeholder list since we can't directly query browser devices from Python
336
+ # This is a fallback; ideally, use a custom component for navigator.mediaDevices.enumerateDevices()
337
+ video_devices = ["Camera 0", "Camera 1"] # Default assumption
338
+ try:
339
+ # Attempt OpenCV detection as a secondary check
340
+ detected = []
341
+ for i in range(10):
342
+ cap = cv2.VideoCapture(i, cv2.CAP_V4L2)
343
+ if not cap.isOpened():
344
+ cap = cv2.VideoCapture(i) # Try default backend
345
+ if cap.isOpened():
346
+ detected.append(f"Camera {i}")
347
+ logger.info(f"Detected camera at index {i}")
348
+ cap.release()
349
+ else:
350
+ logger.debug(f"No camera detected at index {i}")
351
+ if detected:
352
+ video_devices = detected
 
353
  else:
354
+ logger.warning("OpenCV detected no cameras; using browser-inferred defaults")
355
+ except Exception as e:
356
+ logger.error(f"Error detecting video devices with OpenCV: {str(e)}")
357
  return video_devices
358
 
359
  def mock_search(query: str) -> str:
 
552
  st.header("Camera Snap 📷 (Dual Capture!)")
553
  video_devices = get_available_video_devices()
554
  st.subheader("Camera Settings ⚙️")
555
+ st.write(f"Available Cameras: {', '.join(video_devices)}")
556
+ st.info("Camera selection is informational. Use your browser settings to switch cameras (e.g., Chrome > Settings > Privacy > Camera).")
557
+
 
 
558
  # Camera selection with defaults
559
+ default_cam0_index = 0
560
+ default_cam1_index = 1 if len(video_devices) > 1 else 0
561
  selected_cam0 = st.selectbox("Select Camera 0", video_devices, index=default_cam0_index, key="cam0_select")
562
  selected_cam1 = st.selectbox("Select Camera 1", video_devices, index=default_cam1_index, key="cam1_select")
563
 
 
 
564
  slice_count = st.number_input("Image Slice Count 🎞️", min_value=1, max_value=20, value=10, help="How many snaps to dream of? (Automation’s on vacation! 😜)")
565
  video_length = st.number_input("Video Dream Length (seconds) 🎥", min_value=1, max_value=30, value=10, help="Imagine a vid this long—sadly, we’re stuck with pics for now! 😂")
566