Update app.py
Browse files
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
|
333 |
|
334 |
def get_available_video_devices():
|
335 |
-
#
|
336 |
-
|
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)
|
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
|
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
|
432 |
-
st.sidebar.success("Snapshots zipped
|
433 |
else:
|
434 |
-
st.sidebar.warning("No
|
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("
|
441 |
update_gallery()
|
442 |
else:
|
443 |
-
st.sidebar.warning("Nothing to delete! ๐ธ Snap some pics
|
444 |
|
445 |
-
uploaded_files = st.sidebar.file_uploader("Upload
|
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"
|
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"
|
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"
|
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"
|
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"
|
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.
|
555 |
-
st.
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
567 |
cols = st.columns(2)
|
568 |
with cols[0]:
|
569 |
-
st.subheader(f"Camera 0 ({
|
570 |
-
cam0_img = st.camera_input(
|
|
|
|
|
|
|
|
|
|
|
|
|
571 |
if cam0_img:
|
572 |
-
filename = generate_filename(
|
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("๐จ
|
580 |
with cols[1]:
|
581 |
-
st.subheader(f"Camera 1 ({
|
582 |
-
cam1_img = st.camera_input(
|
|
|
|
|
|
|
|
|
|
|
|
|
583 |
if cam1_img:
|
584 |
-
filename = generate_filename(
|
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("๐จ
|
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!)")
|