awacke1 commited on
Commit
6b95d66
ยท
verified ยท
1 Parent(s): 9f7c23f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -51
app.py CHANGED
@@ -283,7 +283,7 @@ def generate_filename(sequence, ext="png"):
283
  import pytz
284
  central = pytz.timezone('US/Central')
285
  dt = datetime.now(central)
286
- return f"{dt.strftime('%m-%d-%Y-%I-%M-%S-%p')}.{ext}"
287
 
288
  def get_download_link(file_path, mime_type="text/plain", label="Download"):
289
  try:
@@ -329,31 +329,25 @@ def update_gallery():
329
  for idx, file in enumerate(media_files[:gallery_size * 2]):
330
  with cols[idx % 2]:
331
  st.image(Image.open(file), caption=file, use_container_width=True)
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:
@@ -428,21 +422,21 @@ with col1:
428
  if media_files:
429
  zip_path = f"snapshot_collection_{int(time.time())}.zip"
430
  zip_files(media_files, zip_path)
431
- st.sidebar.markdown(get_download_link(zip_path, "application/zip", "Download All Snapshots"), unsafe_allow_html=True)
432
- st.sidebar.success("Snapshots zipped and ready! ๐ŸŽ‰ Grab your loot!")
433
  else:
434
- st.sidebar.warning("No snapshots to zip! ๐Ÿ“ธ Snap some pics first!")
435
  with col2:
436
  if st.button("Delete All ๐Ÿ—‘๏ธ"):
437
  media_files = get_gallery_files(["png"])
438
  if media_files:
439
  delete_files(media_files)
440
- st.sidebar.success("All snapshots vanquished! ๐Ÿงน Gallery cleared!")
441
  update_gallery()
442
  else:
443
- st.sidebar.warning("Nothing to delete! ๐Ÿ“ธ Snap some pics to clear later!")
444
 
445
- uploaded_files = st.sidebar.file_uploader("Upload Files ๐ŸŽต๐ŸŽฅ๐Ÿ–ผ๏ธ๐Ÿ“๐Ÿ“œ", type=["mp3", "mp4", "png", "jpeg", "md", "pdf", "docx"], accept_multiple_files=True)
446
  if uploaded_files:
447
  for uploaded_file in uploaded_files:
448
  filename = uploaded_file.name
@@ -455,14 +449,14 @@ audio_files = get_gallery_files(["mp3"])
455
  if audio_files:
456
  for file in audio_files[:gallery_size]:
457
  st.sidebar.audio(file, format="audio/mp3")
458
- st.sidebar.markdown(get_download_link(file, "audio/mp3", f"Download {file}"), unsafe_allow_html=True)
459
 
460
  st.sidebar.subheader("Video Gallery ๐ŸŽฅ")
461
  video_files = get_gallery_files(["mp4"])
462
  if video_files:
463
  for file in video_files[:gallery_size]:
464
  st.sidebar.video(file, format="video/mp4")
465
- st.sidebar.markdown(get_download_link(file, "video/mp4", f"Download {file}"), unsafe_allow_html=True)
466
 
467
  st.sidebar.subheader("Image Gallery ๐Ÿ–ผ๏ธ")
468
  image_files = get_gallery_files(["png", "jpeg"])
@@ -471,7 +465,7 @@ if image_files:
471
  for idx, file in enumerate(image_files[:gallery_size * 2]):
472
  with cols[idx % 2]:
473
  st.image(Image.open(file), caption=file, use_container_width=True)
474
- st.markdown(get_download_link(file, "image/png" if file.endswith(".png") else "image/jpeg", f"Download {file}"), unsafe_allow_html=True)
475
 
476
  st.sidebar.subheader("Markdown Gallery ๐Ÿ“")
477
  md_files = get_gallery_files(["md"])
@@ -479,14 +473,14 @@ if md_files:
479
  for file in md_files[:gallery_size]:
480
  with open(file, "r") as f:
481
  st.sidebar.markdown(f.read())
482
- st.sidebar.markdown(get_download_link(file, "text/markdown", f"Download {file}"), unsafe_allow_html=True)
483
 
484
  st.sidebar.subheader("Document Gallery ๐Ÿ“œ")
485
  doc_files = get_gallery_files(["pdf", "docx"])
486
  if doc_files:
487
  for file in doc_files[:gallery_size]:
488
  mime_type = "application/pdf" if file.endswith(".pdf") else "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
489
- st.sidebar.markdown(get_download_link(file, mime_type, f"Download {file}"), unsafe_allow_html=True)
490
 
491
  st.sidebar.subheader("Model Management ๐Ÿ—‚๏ธ")
492
  model_type = st.sidebar.selectbox("Model Type", ["Causal LM", "Diffusion"])
@@ -549,46 +543,73 @@ with tab1:
549
  st.error(f"Model build failed: {str(e)} ๐Ÿ’ฅ (Check logs for details!)")
550
 
551
  with tab2:
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
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  cols = st.columns(2)
568
  with cols[0]:
569
- st.subheader(f"Camera 0 ({selected_cam0}) ๐ŸŽฌ")
570
- cam0_img = st.camera_input("Snap a Shot - Cam 0 ๐Ÿ“ธ", key="cam0", help="Click to capture a heroic moment! ๐Ÿฆธโ€โ™‚๏ธ")
 
 
 
 
 
 
571
  if cam0_img:
572
- filename = generate_filename(0)
573
  with open(filename, "wb") as f:
574
  f.write(cam0_img.getvalue())
575
  st.image(Image.open(filename), caption=filename, use_container_width=True)
576
  logger.info(f"Saved snapshot from Camera 0: {filename}")
577
  st.session_state['captured_images'].append(filename)
578
  update_gallery()
579
- st.info("๐Ÿšจ Multi-frame captureโ€™s on strike! Snap one at a timeโ€”your Titanโ€™s too cool for automation glitches! ๐Ÿ˜Ž")
580
  with cols[1]:
581
- st.subheader(f"Camera 1 ({selected_cam1}) ๐ŸŽฅ")
582
- cam1_img = st.camera_input("Snap a Shot - Cam 1 ๐Ÿ“ธ", key="cam1", help="Grab another epic frame! ๐ŸŒŸ")
 
 
 
 
 
 
583
  if cam1_img:
584
- filename = generate_filename(1)
585
  with open(filename, "wb") as f:
586
  f.write(cam1_img.getvalue())
587
  st.image(Image.open(filename), caption=filename, use_container_width=True)
588
  logger.info(f"Saved snapshot from Camera 1: {filename}")
589
  st.session_state['captured_images'].append(filename)
590
  update_gallery()
591
- st.info("๐Ÿšจ Frame bursts? Nope, manual snaps only! One click, one masterpiece! ๐ŸŽจ")
592
 
593
  with tab3:
594
  st.header("Fine-Tune Titan (NLP) ๐Ÿ”ง (Teach Your Word Wizard Some Tricks!)")
@@ -606,7 +627,7 @@ with tab3:
606
  writer = csv.DictWriter(f, fieldnames=["prompt", "response"])
607
  writer.writeheader()
608
  writer.writerows(sample_data)
609
- st.markdown(get_download_link(csv_path, "text/csv", "Download Sample CSV"), unsafe_allow_html=True)
610
  st.success(f"Sample CSV generated as {csv_path}! โœ… (Fresh from the data oven!)")
611
  uploaded_csv = st.file_uploader("Upload CSV for SFT ๐Ÿ“œ", type="csv", help="Feed your Titan some tasty prompt-response pairs! ๐Ÿฝ๏ธ")
612
  if uploaded_csv and st.button("Fine-Tune with Uploaded CSV ๐Ÿ”„"):
@@ -622,7 +643,7 @@ with tab3:
622
  status.update(label="Fine-tuning completed! ๐ŸŽ‰ (Wordsmith Titan unleashed!)", state="complete")
623
  zip_path = f"{new_config.model_path}.zip"
624
  zip_files([new_config.model_path], zip_path)
625
- st.markdown(get_download_link(zip_path, "application/zip", "Download Fine-Tuned NLP Titan"), unsafe_allow_html=True)
626
 
627
  with tab4:
628
  st.header("Test Titan (NLP) ๐Ÿงช (Put Your Word Wizard to the Test!)")
@@ -721,14 +742,14 @@ with tab6:
721
  status.update(label="Fine-tuning completed! ๐ŸŽ‰ (Pixel Titan unleashed!)", state="complete")
722
  zip_path = f"{new_config.model_path}.zip"
723
  zip_files([new_config.model_path], zip_path)
724
- st.markdown(get_download_link(zip_path, "application/zip", "Download Fine-Tuned CV Titan"), unsafe_allow_html=True)
725
  csv_path = f"sft_dataset_{int(time.time())}.csv"
726
  with open(csv_path, "w", newline="") as f:
727
  writer = csv.writer(f)
728
  writer.writerow(["image", "text"])
729
  for _, row in edited_data.iterrows():
730
  writer.writerow([row["image"], row["text"]])
731
- st.markdown(get_download_link(csv_path, "text/csv", "Download SFT Dataset CSV"), unsafe_allow_html=True)
732
 
733
  with tab7:
734
  st.header("Test Titan (CV) ๐Ÿงช (Unleash Your Pixel Power!)")
 
283
  import pytz
284
  central = pytz.timezone('US/Central')
285
  dt = datetime.now(central)
286
+ return f"{dt.strftime('%m-%d-%Y-%I-%M-%S-%p')}-{sequence}.{ext}"
287
 
288
  def get_download_link(file_path, mime_type="text/plain", label="Download"):
289
  try:
 
329
  for idx, file in enumerate(media_files[:gallery_size * 2]):
330
  with cols[idx % 2]:
331
  st.image(Image.open(file), caption=file, use_container_width=True)
332
+ st.markdown(get_download_link(file, "image/png", "Download Snap ๐Ÿ“ธ"), unsafe_allow_html=True)
333
 
334
  def get_available_video_devices():
335
+ # Assuming 6 cameras as per your setup; adjust if needed
336
+ video_devices = [f"Camera {i} ๐ŸŽฅ" for i in range(6)]
 
337
  try:
 
338
  detected = []
339
  for i in range(10):
340
  cap = cv2.VideoCapture(i, cv2.CAP_V4L2)
341
  if not cap.isOpened():
342
+ cap = cv2.VideoCapture(i)
343
  if cap.isOpened():
344
+ detected.append(f"Camera {i} ๐ŸŽฅ")
345
  logger.info(f"Detected camera at index {i}")
346
  cap.release()
 
 
347
  if detected:
348
+ video_devices = detected[:6] # Limit to 6 as per your spec
 
 
349
  except Exception as e:
350
+ logger.error(f"Error detecting cameras: {str(e)}")
351
  return video_devices
352
 
353
  def mock_search(query: str) -> str:
 
422
  if media_files:
423
  zip_path = f"snapshot_collection_{int(time.time())}.zip"
424
  zip_files(media_files, zip_path)
425
+ st.sidebar.markdown(get_download_link(zip_path, "application/zip", "Download All Snaps ๐Ÿ“ฆ"), unsafe_allow_html=True)
426
+ st.sidebar.success("Snapshots zipped! ๐ŸŽ‰ Grab your loot!")
427
  else:
428
+ st.sidebar.warning("No snaps to zip! ๐Ÿ“ธ Snap some first!")
429
  with col2:
430
  if st.button("Delete All ๐Ÿ—‘๏ธ"):
431
  media_files = get_gallery_files(["png"])
432
  if media_files:
433
  delete_files(media_files)
434
+ st.sidebar.success("Snaps vanquished! ๐Ÿงน Gallery cleared!")
435
  update_gallery()
436
  else:
437
+ st.sidebar.warning("Nothing to delete! ๐Ÿ“ธ Snap some pics!")
438
 
439
+ uploaded_files = st.sidebar.file_uploader("Upload Goodies ๐ŸŽต๐ŸŽฅ๐Ÿ–ผ๏ธ๐Ÿ“๐Ÿ“œ", type=["mp3", "mp4", "png", "jpeg", "md", "pdf", "docx"], accept_multiple_files=True)
440
  if uploaded_files:
441
  for uploaded_file in uploaded_files:
442
  filename = uploaded_file.name
 
449
  if audio_files:
450
  for file in audio_files[:gallery_size]:
451
  st.sidebar.audio(file, format="audio/mp3")
452
+ st.sidebar.markdown(get_download_link(file, "audio/mp3", f"Grab Tune ๐ŸŽต"), unsafe_allow_html=True)
453
 
454
  st.sidebar.subheader("Video Gallery ๐ŸŽฅ")
455
  video_files = get_gallery_files(["mp4"])
456
  if video_files:
457
  for file in video_files[:gallery_size]:
458
  st.sidebar.video(file, format="video/mp4")
459
+ st.sidebar.markdown(get_download_link(file, "video/mp4", f"Snag Clip ๐ŸŽฌ"), unsafe_allow_html=True)
460
 
461
  st.sidebar.subheader("Image Gallery ๐Ÿ–ผ๏ธ")
462
  image_files = get_gallery_files(["png", "jpeg"])
 
465
  for idx, file in enumerate(image_files[:gallery_size * 2]):
466
  with cols[idx % 2]:
467
  st.image(Image.open(file), caption=file, use_container_width=True)
468
+ st.markdown(get_download_link(file, "image/png" if file.endswith(".png") else "image/jpeg", f"Save Pic ๐Ÿ–ผ๏ธ"), unsafe_allow_html=True)
469
 
470
  st.sidebar.subheader("Markdown Gallery ๐Ÿ“")
471
  md_files = get_gallery_files(["md"])
 
473
  for file in md_files[:gallery_size]:
474
  with open(file, "r") as f:
475
  st.sidebar.markdown(f.read())
476
+ st.sidebar.markdown(get_download_link(file, "text/markdown", f"Get Note ๐Ÿ“"), unsafe_allow_html=True)
477
 
478
  st.sidebar.subheader("Document Gallery ๐Ÿ“œ")
479
  doc_files = get_gallery_files(["pdf", "docx"])
480
  if doc_files:
481
  for file in doc_files[:gallery_size]:
482
  mime_type = "application/pdf" if file.endswith(".pdf") else "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
483
+ st.sidebar.markdown(get_download_link(file, mime_type, f"Fetch Doc ๐Ÿ“œ"), unsafe_allow_html=True)
484
 
485
  st.sidebar.subheader("Model Management ๐Ÿ—‚๏ธ")
486
  model_type = st.sidebar.selectbox("Model Type", ["Causal LM", "Diffusion"])
 
543
  st.error(f"Model build failed: {str(e)} ๐Ÿ’ฅ (Check logs for details!)")
544
 
545
  with tab2:
546
+ st.header("Camera Snap ๐Ÿ“ท (Dual Capture Fiesta!)")
547
  video_devices = get_available_video_devices()
548
+ st.write(f"๐ŸŽ‰ Detected Cameras: {', '.join(video_devices)}")
549
+ st.info("Switch cams in your browser settings (e.g., Chrome > Privacy > Camera) since Iโ€™m a browser star! ๐ŸŒŸ")
550
+
551
+ # Camera 0 Settings
552
+ st.subheader("Camera 0 ๐ŸŽฌ - Lights, Camera, Action!")
553
+ cam0_cols = st.columns(4)
554
+ with cam0_cols[0]:
555
+ cam0_device = st.selectbox("Cam ๐Ÿ“ท", video_devices, index=0, key="cam0_device", help="Pick your star cam! ๐ŸŒŸ")
556
+ with cam0_cols[1]:
557
+ cam0_label = st.text_input("Tag ๐Ÿท๏ธ", "Cam 0 Snap", key="cam0_label", help="Name your masterpiece! ๐ŸŽจ")
558
+ with cam0_cols[2]:
559
+ cam0_help = st.text_input("Hint ๐Ÿ’ก", "Snap a heroic moment! ๐Ÿฆธโ€โ™‚๏ธ", key="cam0_help", help="Give a fun tip!")
560
+ with cam0_cols[3]:
561
+ cam0_vis = st.selectbox("Show ๐Ÿ–ผ๏ธ", ["visible", "hidden", "collapsed"], index=0, key="cam0_vis", help="Label vibes: Visible, Sneaky, or Gone!")
562
+
563
+ # Camera 1 Settings
564
+ st.subheader("Camera 1 ๐ŸŽฅ - Roll the Film!")
565
+ cam1_cols = st.columns(4)
566
+ with cam1_cols[0]:
567
+ cam1_device = st.selectbox("Cam ๐Ÿ“ท", video_devices, index=1 if len(video_devices) > 1 else 0, key="cam1_device", help="Choose your blockbuster cam! ๐ŸŽฌ")
568
+ with cam1_cols[1]:
569
+ cam1_label = st.text_input("Tag ๐Ÿท๏ธ", "Cam 1 Snap", key="cam1_label", help="Title your epic shot! ๐ŸŒ ")
570
+ with cam1_cols[2]:
571
+ cam1_help = st.text_input("Hint ๐Ÿ’ก", "Grab an epic frame! ๐ŸŒŸ", key="cam1_help", help="Drop a cheeky hint!")
572
+ with cam1_cols[3]:
573
+ cam1_vis = st.selectbox("Show ๐Ÿ–ผ๏ธ", ["visible", "hidden", "collapsed"], index=0, key="cam1_vis", help="Label style: Show it, Hide it, Poof!")
574
+
575
+ # Capture Widgets
576
  cols = st.columns(2)
577
  with cols[0]:
578
+ st.subheader(f"Camera 0 ({cam0_device}) ๐ŸŽฌ")
579
+ cam0_img = st.camera_input(
580
+ label=cam0_label,
581
+ key="cam0",
582
+ help=cam0_help,
583
+ disabled=False,
584
+ label_visibility=cam0_vis
585
+ )
586
  if cam0_img:
587
+ filename = generate_filename("cam0")
588
  with open(filename, "wb") as f:
589
  f.write(cam0_img.getvalue())
590
  st.image(Image.open(filename), caption=filename, use_container_width=True)
591
  logger.info(f"Saved snapshot from Camera 0: {filename}")
592
  st.session_state['captured_images'].append(filename)
593
  update_gallery()
594
+ st.info("๐Ÿšจ One snap at a timeโ€”your Titanโ€™s too cool for bursts! ๐Ÿ˜Ž")
595
  with cols[1]:
596
+ st.subheader(f"Camera 1 ({cam1_device}) ๐ŸŽฅ")
597
+ cam1_img = st.camera_input(
598
+ label=cam1_label,
599
+ key="cam1",
600
+ help=cam1_help,
601
+ disabled=False,
602
+ label_visibility=cam1_vis
603
+ )
604
  if cam1_img:
605
+ filename = generate_filename("cam1")
606
  with open(filename, "wb") as f:
607
  f.write(cam1_img.getvalue())
608
  st.image(Image.open(filename), caption=filename, use_container_width=True)
609
  logger.info(f"Saved snapshot from Camera 1: {filename}")
610
  st.session_state['captured_images'].append(filename)
611
  update_gallery()
612
+ st.info("๐Ÿšจ Single shots onlyโ€”craft your masterpiece! ๐ŸŽจ")
613
 
614
  with tab3:
615
  st.header("Fine-Tune Titan (NLP) ๐Ÿ”ง (Teach Your Word Wizard Some Tricks!)")
 
627
  writer = csv.DictWriter(f, fieldnames=["prompt", "response"])
628
  writer.writeheader()
629
  writer.writerows(sample_data)
630
+ st.markdown(get_download_link(csv_path, "text/csv", "Download Sample CSV ๐Ÿ“œ"), unsafe_allow_html=True)
631
  st.success(f"Sample CSV generated as {csv_path}! โœ… (Fresh from the data oven!)")
632
  uploaded_csv = st.file_uploader("Upload CSV for SFT ๐Ÿ“œ", type="csv", help="Feed your Titan some tasty prompt-response pairs! ๐Ÿฝ๏ธ")
633
  if uploaded_csv and st.button("Fine-Tune with Uploaded CSV ๐Ÿ”„"):
 
643
  status.update(label="Fine-tuning completed! ๐ŸŽ‰ (Wordsmith Titan unleashed!)", state="complete")
644
  zip_path = f"{new_config.model_path}.zip"
645
  zip_files([new_config.model_path], zip_path)
646
+ st.markdown(get_download_link(zip_path, "application/zip", "Download Fine-Tuned NLP Titan ๐Ÿ“ฆ"), unsafe_allow_html=True)
647
 
648
  with tab4:
649
  st.header("Test Titan (NLP) ๐Ÿงช (Put Your Word Wizard to the Test!)")
 
742
  status.update(label="Fine-tuning completed! ๐ŸŽ‰ (Pixel Titan unleashed!)", state="complete")
743
  zip_path = f"{new_config.model_path}.zip"
744
  zip_files([new_config.model_path], zip_path)
745
+ st.markdown(get_download_link(zip_path, "application/zip", "Download Fine-Tuned CV Titan ๐Ÿ“ฆ"), unsafe_allow_html=True)
746
  csv_path = f"sft_dataset_{int(time.time())}.csv"
747
  with open(csv_path, "w", newline="") as f:
748
  writer = csv.writer(f)
749
  writer.writerow(["image", "text"])
750
  for _, row in edited_data.iterrows():
751
  writer.writerow([row["image"], row["text"]])
752
+ st.markdown(get_download_link(csv_path, "text/csv", "Download SFT Dataset CSV ๐Ÿ“œ"), unsafe_allow_html=True)
753
 
754
  with tab7:
755
  st.header("Test Titan (CV) ๐Ÿงช (Unleash Your Pixel Power!)")