import streamlit as st import pandas as pd from datetime import datetime import os import threading import time import base64 # ππ₯ Initialize session state like a galactic DJ spinning tracks! if 'file_history' not in st.session_state: st.session_state['file_history'] = [] if 'auto_capture_running' not in st.session_state: st.session_state['auto_capture_running'] = False if 'snapshot_data' not in st.session_state: st.session_state['snapshot_data'] = None # ππΎ Save to history like a time-traveling scribe! | π β¨ save_to_history("πΌοΈ Image", "pic.jpg") - Stamps a pic in the history books like a boss! def save_to_history(file_type, file_path): timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") st.session_state['file_history'].append({ "Timestamp": timestamp, "Type": file_type, "Path": file_path }) # πΈβ° Auto-capture every 10 secs like a sneaky shutterbug! def auto_capture(): if st.session_state['auto_capture_running'] and st.session_state['snapshot_data']: snapshot_data = st.session_state['snapshot_data'] filename = f"auto_snap_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg" with open(filename, "wb") as f: f.write(base64.b64decode(snapshot_data.split(',')[1])) save_to_history("πΌοΈ Image", filename) threading.Timer(10, auto_capture).start() # ποΈ Sidebar config like a spaceship control panel! with st.sidebar: st.header("ποΈπΈ Snap Shack") if st.button("β° Start Auto-Snap"): st.session_state['auto_capture_running'] = True auto_capture() if st.button("βΉοΈ Stop Auto-Snap"): st.session_state['auto_capture_running'] = False # π Sidebar file outline with emoji flair! st.subheader("π Snap Stash") if st.session_state['file_history']: images = [f for f in st.session_state['file_history'] if f['Type'] == "πΌοΈ Image"] if images: st.write("πΌοΈ Images") for img in images: st.write(f"- {img['Path']} @ {img['Timestamp']}") else: st.write("π³οΈ Empty Stash!") # ππ¨ Main UI kicks off like a cosmic art show! st.title("πΈ WebRTC Snap Craze") # πΈπ· WebRTC camera snap zone! st.header("πΈπ₯ Snap Zone") webrtc_html = """