Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,10 +53,6 @@ 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 |
-
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,20 +340,6 @@ def get_available_video_devices():
|
|
| 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."
|
|
@@ -555,59 +537,46 @@ with tab2:
|
|
| 555 |
video_devices = get_available_video_devices()
|
| 556 |
st.subheader("Camera Settings ⚙️")
|
| 557 |
if not video_devices:
|
| 558 |
-
st.warning("No video devices detected! 📷
|
| 559 |
else:
|
| 560 |
st.write(f"Detected Video Devices: {', '.join(video_devices)}")
|
| 561 |
|
| 562 |
# Camera selection with defaults
|
| 563 |
default_cam0_index = 0 if video_devices else -1
|
| 564 |
default_cam1_index = 1 if len(video_devices) > 1 else (0 if video_devices else -1)
|
| 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 |
-
|
| 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}) 🎬"
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 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}) 🎥"
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 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!)")
|
|
|
|
| 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 |
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."
|
|
|
|
| 537 |
video_devices = get_available_video_devices()
|
| 538 |
st.subheader("Camera Settings ⚙️")
|
| 539 |
if not video_devices:
|
| 540 |
+
st.warning("No video devices detected by OpenCV! 📷 Browser may still access cameras; ensure permissions are granted.")
|
| 541 |
else:
|
| 542 |
st.write(f"Detected Video Devices: {', '.join(video_devices)}")
|
| 543 |
|
| 544 |
# Camera selection with defaults
|
| 545 |
default_cam0_index = 0 if video_devices else -1
|
| 546 |
default_cam1_index = 1 if len(video_devices) > 1 else (0 if video_devices else -1)
|
| 547 |
+
selected_cam0 = st.selectbox("Select Camera 0", video_devices or ["Browser Default"], index=default_cam0_index if video_devices else 0, key="cam0_select")
|
| 548 |
+
selected_cam1 = st.selectbox("Select Camera 1", video_devices or ["Browser Default"], index=default_cam1_index if video_devices else 0, key="cam1_select")
|
| 549 |
|
| 550 |
+
st.info("Note: Camera selection is informational. Actual device used depends on browser settings.")
|
|
|
|
|
|
|
| 551 |
|
| 552 |
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! 😜)")
|
| 553 |
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! 😂")
|
| 554 |
|
| 555 |
cols = st.columns(2)
|
| 556 |
with cols[0]:
|
| 557 |
+
st.subheader(f"Camera 0 ({selected_cam0}) 🎬")
|
| 558 |
+
cam0_img = st.camera_input("Snap a Shot - Cam 0 📸", key="cam0", help="Click to capture a heroic moment! 🦸♂️")
|
| 559 |
+
if cam0_img:
|
| 560 |
+
filename = generate_filename(0)
|
| 561 |
+
with open(filename, "wb") as f:
|
| 562 |
+
f.write(cam0_img.getvalue())
|
| 563 |
+
st.image(Image.open(filename), caption=filename, use_container_width=True)
|
| 564 |
+
logger.info(f"Saved snapshot from Camera 0: {filename}")
|
| 565 |
+
st.session_state['captured_images'].append(filename)
|
| 566 |
+
update_gallery()
|
| 567 |
+
st.info("🚨 Multi-frame capture’s on strike! Snap one at a time—your Titan’s too cool for automation glitches! 😎")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
with cols[1]:
|
| 569 |
+
st.subheader(f"Camera 1 ({selected_cam1}) 🎥")
|
| 570 |
+
cam1_img = st.camera_input("Snap a Shot - Cam 1 📸", key="cam1", help="Grab another epic frame! 🌟")
|
| 571 |
+
if cam1_img:
|
| 572 |
+
filename = generate_filename(1)
|
| 573 |
+
with open(filename, "wb") as f:
|
| 574 |
+
f.write(cam1_img.getvalue())
|
| 575 |
+
st.image(Image.open(filename), caption=filename, use_container_width=True)
|
| 576 |
+
logger.info(f"Saved snapshot from Camera 1: {filename}")
|
| 577 |
+
st.session_state['captured_images'].append(filename)
|
| 578 |
+
update_gallery()
|
| 579 |
+
st.info("🚨 Frame bursts? Nope, manual snaps only! One click, one masterpiece! 🎨")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
|
| 581 |
with tab3:
|
| 582 |
st.header("Fine-Tune Titan (NLP) 🔧 (Teach Your Word Wizard Some Tricks!)")
|