awacke1 commited on
Commit
f7e2b3e
·
verified ·
1 Parent(s): 8b72d19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -20
app.py CHANGED
@@ -53,6 +53,10 @@ if 'cv_loaded' not in st.session_state:
53
  st.session_state['cv_loaded'] = False
54
  if 'active_tab' not in st.session_state:
55
  st.session_state['active_tab'] = "Build Titan 🌱"
 
 
 
 
56
 
57
  @dataclass
58
  class ModelConfig:
@@ -340,6 +344,20 @@ def get_available_video_devices():
340
  cap.release()
341
  return video_devices
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  def mock_search(query: str) -> str:
344
  if "superhero" in query.lower():
345
  return "Latest trends: Gold-plated Batman statues, VR superhero battles."
@@ -547,34 +565,49 @@ with tab2:
547
  selected_cam0 = st.selectbox("Select Camera 0", video_devices, index=default_cam0_index, key="cam0_select")
548
  selected_cam1 = st.selectbox("Select Camera 1", video_devices, index=default_cam1_index, key="cam1_select")
549
 
 
 
 
 
550
  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! 😜)")
551
  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! 😂")
552
 
553
  cols = st.columns(2)
554
  with cols[0]:
555
  st.subheader(f"Camera 0 ({selected_cam0}) 🎬" if selected_cam0 else "Camera 0 (None Detected)")
556
- cam0_img = st.camera_input("Snap a Shot - Cam 0 📸", key="cam0", help="Click to capture a heroic moment! 🦸‍♂️")
557
- if cam0_img:
558
- filename = generate_filename(0)
559
- with open(filename, "wb") as f:
560
- f.write(cam0_img.getvalue())
561
- st.image(Image.open(filename), caption=filename, use_container_width=True)
562
- logger.info(f"Saved snapshot from Camera 0: {filename}")
563
- st.session_state['captured_images'].append(filename)
564
- update_gallery()
565
- st.info("🚨 Multi-frame capture’s on strike! Snap one at a time—your Titan’s too cool for automation glitches! 😎")
 
 
 
 
 
 
566
  with cols[1]:
567
  st.subheader(f"Camera 1 ({selected_cam1}) 🎥" if selected_cam1 else "Camera 1 (None Detected)")
568
- cam1_img = st.camera_input("Snap a Shot - Cam 1 📸", key="cam1", help="Grab another epic frame! 🌟")
569
- if cam1_img:
570
- filename = generate_filename(1)
571
- with open(filename, "wb") as f:
572
- f.write(cam1_img.getvalue())
573
- st.image(Image.open(filename), caption=filename, use_container_width=True)
574
- logger.info(f"Saved snapshot from Camera 1: {filename}")
575
- st.session_state['captured_images'].append(filename)
576
- update_gallery()
577
- st.info("🚨 Frame bursts? Nope, manual snaps only! One click, one masterpiece! 🎨")
 
 
 
 
 
578
 
579
  with tab3:
580
  st.header("Fine-Tune Titan (NLP) 🔧 (Teach Your Word Wizard Some Tricks!)")
 
53
  st.session_state['cv_loaded'] = False
54
  if 'active_tab' not in st.session_state:
55
  st.session_state['active_tab'] = "Build Titan 🌱"
56
+ if 'cam0_index' not in st.session_state:
57
+ st.session_state['cam0_index'] = 0
58
+ if 'cam1_index' not in st.session_state:
59
+ st.session_state['cam1_index'] = 1
60
 
61
  @dataclass
62
  class ModelConfig:
 
344
  cap.release()
345
  return video_devices
346
 
347
+ def capture_frame(device_index):
348
+ cap = cv2.VideoCapture(device_index)
349
+ if not cap.isOpened():
350
+ logger.error(f"Failed to open camera at index {device_index}")
351
+ return None
352
+ ret, frame = cap.read()
353
+ if ret:
354
+ # Convert BGR to RGB for PIL compatibility
355
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
356
+ cap.release()
357
+ return Image.fromarray(frame_rgb)
358
+ cap.release()
359
+ return None
360
+
361
  def mock_search(query: str) -> str:
362
  if "superhero" in query.lower():
363
  return "Latest trends: Gold-plated Batman statues, VR superhero battles."
 
565
  selected_cam0 = st.selectbox("Select Camera 0", video_devices, index=default_cam0_index, key="cam0_select")
566
  selected_cam1 = st.selectbox("Select Camera 1", video_devices, index=default_cam1_index, key="cam1_select")
567
 
568
+ # Store selected indices in session state
569
+ st.session_state['cam0_index'] = int(selected_cam0.split()[-1]) if selected_cam0 else 0
570
+ st.session_state['cam1_index'] = int(selected_cam1.split()[-1]) if selected_cam1 else (1 if len(video_devices) > 1 else 0)
571
+
572
  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! 😜)")
573
  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! 😂")
574
 
575
  cols = st.columns(2)
576
  with cols[0]:
577
  st.subheader(f"Camera 0 ({selected_cam0}) 🎬" if selected_cam0 else "Camera 0 (None Detected)")
578
+ if st.button("Snap a Shot - Cam 0 📸", key="cam0_button"):
579
+ if video_devices:
580
+ frame = capture_frame(st.session_state['cam0_index'])
581
+ if frame:
582
+ filename = generate_filename(0)
583
+ frame.save(filename)
584
+ st.image(frame, caption=filename, use_container_width=True)
585
+ logger.info(f"Saved snapshot from Camera 0: {filename}")
586
+ st.session_state['captured_images'].append(filename)
587
+ update_gallery()
588
+ else:
589
+ st.error("Failed to capture from Camera 0!")
590
+ else:
591
+ st.error("No camera available to capture from!")
592
+ st.info("🚨 Multi-frame capture not implemented! Snap one at a time.")
593
+
594
  with cols[1]:
595
  st.subheader(f"Camera 1 ({selected_cam1}) 🎥" if selected_cam1 else "Camera 1 (None Detected)")
596
+ if st.button("Snap a Shot - Cam 1 📸", key="cam1_button"):
597
+ if video_devices:
598
+ frame = capture_frame(st.session_state['cam1_index'])
599
+ if frame:
600
+ filename = generate_filename(1)
601
+ frame.save(filename)
602
+ st.image(frame, caption=filename, use_container_width=True)
603
+ logger.info(f"Saved snapshot from Camera 1: {filename}")
604
+ st.session_state['captured_images'].append(filename)
605
+ update_gallery()
606
+ else:
607
+ st.error("Failed to capture from Camera 1!")
608
+ else:
609
+ st.error("No camera available to capture from!")
610
+ st.info("🚨 Multi-frame capture not implemented! Snap one at a time.")
611
 
612
  with tab3:
613
  st.header("Fine-Tune Titan (NLP) 🔧 (Teach Your Word Wizard Some Tricks!)")