Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
-
import cv2
|
5 |
-
from pydub import AudioSegment
|
6 |
-
import imageio
|
7 |
-
import av
|
8 |
-
import moviepy as mp
|
9 |
import os
|
10 |
-
import numpy as np
|
11 |
-
from io import BytesIO
|
12 |
import threading
|
13 |
import time
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# ππ₯ Initialize session state like a galactic DJ spinning tracks!
|
16 |
if 'file_history' not in st.session_state:
|
17 |
st.session_state['file_history'] = []
|
18 |
-
if '
|
19 |
-
st.session_state['ping_code'] = ""
|
20 |
-
if 'uploaded_files' not in st.session_state:
|
21 |
-
st.session_state['uploaded_files'] = []
|
22 |
-
if 'auto_capture_running' not in st.session_state:
|
23 |
st.session_state['auto_capture_running'] = False
|
|
|
|
|
24 |
|
25 |
-
# ππΎ Save to history like a time-traveling scribe! | π
β¨ save_to_history("Image", "pic.jpg") - Stamps a pic in the history books like a boss!
|
26 |
def save_to_history(file_type, file_path):
|
27 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
28 |
st.session_state['file_history'].append({
|
@@ -33,464 +29,75 @@ def save_to_history(file_type, file_path):
|
|
33 |
|
34 |
# πΈβ° Auto-capture every 10 secs like a sneaky shutterbug!
|
35 |
def auto_capture():
|
36 |
-
if st.session_state['auto_capture_running']:
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
if cap and cap.isOpened():
|
44 |
-
ret, frame = cap.read()
|
45 |
-
if ret:
|
46 |
-
file_path = f"auto_snap_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
47 |
-
cv2.imwrite(file_path, frame)
|
48 |
-
save_to_history("πΌοΈ Image", file_path)
|
49 |
-
cap.release()
|
50 |
-
else:
|
51 |
-
st.warning("π¨ No camera found!")
|
52 |
threading.Timer(10, auto_capture).start()
|
53 |
|
54 |
# ποΈ Sidebar config like a spaceship control panel!
|
55 |
with st.sidebar:
|
56 |
-
st.header("ποΈπΈ
|
57 |
-
library_choice = st.selectbox("π Pick a Tool", ["OpenCV", "PyDub", "ImageIO", "PyAV", "MoviePy", "JS Audio"])
|
58 |
-
resolution = st.select_slider("π Snap Size", options=["320x240", "640x480", "1280x720"], value="640x480")
|
59 |
-
fps = st.slider("β±οΈ Speed Snap", 1, 60, 30)
|
60 |
if st.button("β° Start Auto-Snap"):
|
61 |
st.session_state['auto_capture_running'] = True
|
62 |
auto_capture()
|
63 |
if st.button("βΉοΈ Stop Auto-Snap"):
|
64 |
st.session_state['auto_capture_running'] = False
|
65 |
|
66 |
-
# π’ DTMF ping code like a retro phone hacker!
|
67 |
-
st.subheader("π Ping-a-Tron")
|
68 |
-
col1, col2, col3, col4 = st.columns(4)
|
69 |
-
with col1:
|
70 |
-
digit1 = st.selectbox("1οΈβ£", [str(i) for i in range(10)], key="d1")
|
71 |
-
with col2:
|
72 |
-
digit2 = st.selectbox("2οΈβ£", [str(i) for i in range(10)], key="d2")
|
73 |
-
with col3:
|
74 |
-
digit3 = st.selectbox("3οΈβ£", [str(i) for i in range(10)], key="d3")
|
75 |
-
with col4:
|
76 |
-
digit4 = st.selectbox("4οΈβ£", [str(i) for i in range(10)], key="d4")
|
77 |
-
ping_code = digit1 + digit2 + digit3 + digit4
|
78 |
-
st.session_state['ping_code'] = ping_code
|
79 |
-
st.write(f"π Code: {ping_code}")
|
80 |
-
|
81 |
# π Sidebar file outline with emoji flair!
|
82 |
-
st.subheader("π
|
83 |
if st.session_state['file_history']:
|
84 |
images = [f for f in st.session_state['file_history'] if f['Type'] == "πΌοΈ Image"]
|
85 |
-
videos = [f for f in st.session_state['file_history'] if f['Type'] in ["π₯ Video", "ποΈ GIF"]]
|
86 |
-
audios = [f for f in st.session_state['file_history'] if f['Type'] == "π΅ Audio"]
|
87 |
if images:
|
88 |
st.write("πΌοΈ Images")
|
89 |
for img in images:
|
90 |
st.write(f"- {img['Path']} @ {img['Timestamp']}")
|
91 |
-
if videos:
|
92 |
-
st.write("π₯ Videos/GIFs")
|
93 |
-
for vid in videos:
|
94 |
-
st.write(f"- {vid['Path']} @ {vid['Timestamp']}")
|
95 |
-
if audios:
|
96 |
-
st.write("π΅ Audios")
|
97 |
-
for aud in audios:
|
98 |
-
st.write(f"- {aud['Path']} @ {aud['Timestamp']}")
|
99 |
else:
|
100 |
-
st.write("π³οΈ Empty
|
101 |
|
102 |
# ππ¨ Main UI kicks off like a cosmic art show!
|
103 |
-
st.title("
|
104 |
-
|
105 |
-
#
|
106 |
-
st.header("
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
st.
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
cap = cv2.VideoCapture(i)
|
119 |
-
if cap.isOpened():
|
120 |
-
break
|
121 |
-
cap.release()
|
122 |
-
if cap and cap.isOpened():
|
123 |
-
frame_placeholder = st.empty()
|
124 |
-
for _ in range(50):
|
125 |
-
ret, frame = cap.read()
|
126 |
-
if ret:
|
127 |
-
frame_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
128 |
-
cap.release()
|
129 |
-
else:
|
130 |
-
st.error("π¨ No camera found!")
|
131 |
-
|
132 |
-
st.write("ποΈβ¨ Gray Snap")
|
133 |
-
if st.button("π· Save Gray", key="opencv_2"):
|
134 |
-
# ποΈβ¨ Saves grayscale like an artsy ghost! | π cv2.imwrite("gray.jpg", cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)) - Ditches color like a moody poet!
|
135 |
-
cap = None
|
136 |
-
for i in range(10):
|
137 |
-
cap = cv2.VideoCapture(i)
|
138 |
-
if cap.isOpened():
|
139 |
-
break
|
140 |
-
cap.release()
|
141 |
-
if cap and cap.isOpened():
|
142 |
-
ret, frame = cap.read()
|
143 |
-
if ret:
|
144 |
-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
145 |
-
file_path = f"opencv_gray_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
146 |
-
cv2.imwrite(file_path, gray)
|
147 |
-
save_to_history("πΌοΈ Image", file_path)
|
148 |
-
st.image(file_path, caption="π€ Gray Vibes")
|
149 |
-
cap.release()
|
150 |
-
else:
|
151 |
-
st.error("π¨ No camera found!")
|
152 |
-
|
153 |
-
st.write("π΅οΈββοΈπ Edge Snap")
|
154 |
-
if st.button("πͺ Edge It", key="opencv_3"):
|
155 |
-
# π΅οΈββοΈπ Finds edges sharper than a detectiveβs wit! | πΌοΈ edges = cv2.Canny(frame, 100, 200) - Outlines like a crime scene sketch!
|
156 |
-
cap = None
|
157 |
-
for i in range(10):
|
158 |
-
cap = cv2.VideoCapture(i)
|
159 |
-
if cap.isOpened():
|
160 |
-
break
|
161 |
-
cap.release()
|
162 |
-
if cap and cap.isOpened():
|
163 |
-
ret, frame = cap.read()
|
164 |
-
if ret:
|
165 |
-
edges = cv2.Canny(frame, 100, 200)
|
166 |
-
file_path = f"opencv_edges_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
167 |
-
cv2.imwrite(file_path, edges)
|
168 |
-
save_to_history("πΌοΈ Image", file_path)
|
169 |
-
st.image(file_path, caption="π Edge Lord")
|
170 |
-
cap.release()
|
171 |
-
else:
|
172 |
-
st.error("π¨ No camera found!")
|
173 |
-
|
174 |
-
# 2. PyDub - ποΈ Audio mixing madness!
|
175 |
-
with st.expander("2οΈβ£ ποΈ PyDub Party"):
|
176 |
-
st.write("π Audio Ace: Mixmaster vibes!")
|
177 |
-
st.subheader("π₯ Top Tricks")
|
178 |
-
|
179 |
-
st.write("π€π©οΈ Load Jam")
|
180 |
-
if st.button("π΅ Load Sound", key="pydub_1"):
|
181 |
-
# π€π©οΈ Grabs audio like a sonic thief! | ποΈ AudioSegment.from_file("sound.wav") - Nabs tracks like a sound bandit!
|
182 |
-
uploaded_audio = st.file_uploader("ποΈ Drop a WAV", type=['wav'], key="pydub_load")
|
183 |
-
if uploaded_audio:
|
184 |
-
sound = AudioSegment.from_file(uploaded_audio)
|
185 |
-
file_path = f"pydub_load_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
|
186 |
-
sound.export(file_path, format="wav")
|
187 |
-
save_to_history("π΅ Audio", file_path)
|
188 |
-
st.audio(file_path)
|
189 |
-
|
190 |
-
st.write("ππ‘ Export Snap")
|
191 |
-
if st.button("πΆ MP3 It", key="pydub_2"):
|
192 |
-
# ππ‘ Spits out tracks like a beat factory! | π΅ sound.export("out.mp3") - Pumps tunes like a hit machine!
|
193 |
-
uploaded_audio = st.file_uploader("ποΈ Drop a WAV", type=['wav'], key="pydub_export")
|
194 |
-
if uploaded_audio:
|
195 |
-
sound = AudioSegment.from_file(uploaded_audio)
|
196 |
-
file_path = f"pydub_mp3_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp3"
|
197 |
-
sound.export(file_path, format="mp3")
|
198 |
-
save_to_history("π΅ Audio", file_path)
|
199 |
-
st.audio(file_path)
|
200 |
-
|
201 |
-
st.write("πΆπΎ Reverse Blast")
|
202 |
-
if st.button("π Flip It", key="pydub_3"):
|
203 |
-
# πΆπΎ Flips sound like a time-travel DJ! | π§ sound.reverse() - Spins audio back like a retro remix!
|
204 |
-
uploaded_audio = st.file_uploader("ποΈ Drop a WAV", type=['wav'], key="pydub_reverse")
|
205 |
-
if uploaded_audio:
|
206 |
-
sound = AudioSegment.from_file(uploaded_audio)
|
207 |
-
reversed_sound = sound.reverse()
|
208 |
-
file_path = f"pydub_rev_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
|
209 |
-
reversed_sound.export(file_path, format="wav")
|
210 |
-
save_to_history("π΅ Audio", file_path)
|
211 |
-
st.audio(file_path)
|
212 |
-
|
213 |
-
# 3. ImageIO - πΌοΈ Pixel playtime!
|
214 |
-
with st.expander("3οΈβ£ πΉ ImageIO Bash"):
|
215 |
-
st.write("π₯ Easy Snap: Pixel lightweight champ!")
|
216 |
-
st.subheader("π₯ Top Tricks")
|
217 |
-
|
218 |
-
st.write("πΉπ Frame Peek")
|
219 |
-
if st.button("πΈ Snap It", key="imageio_1"):
|
220 |
-
# πΉπ Grabs frames like a shy stalker! | π· reader = imageio.get_reader('<video0>') - Sneaks a peek at your cam!
|
221 |
-
try:
|
222 |
-
reader = imageio.get_reader('<video0>')
|
223 |
-
frame = reader.get_next_data()
|
224 |
-
file_path = f"imageio_frame_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
225 |
-
imageio.imwrite(file_path, frame)
|
226 |
-
save_to_history("πΌοΈ Image", file_path)
|
227 |
-
st.image(file_path)
|
228 |
-
except Exception as e:
|
229 |
-
st.error(f"π¨ Camera snag: {str(e)}")
|
230 |
-
|
231 |
-
st.write("π¨οΈπ Crunch Snap")
|
232 |
-
if st.button("π Slim Pic", key="imageio_2"):
|
233 |
-
# π¨οΈπ Compresses like a diet guru! | πΌοΈ imageio.imwrite("pic.jpg", frame, quality=85) - Shrinks pics like a tight squeeze!
|
234 |
-
try:
|
235 |
-
reader = imageio.get_reader('<video0>')
|
236 |
-
frame = reader.get_next_data()
|
237 |
-
file_path = f"imageio_comp_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
238 |
-
imageio.imwrite(file_path, frame, quality=85)
|
239 |
-
save_to_history("πΌοΈ Image", file_path)
|
240 |
-
st.image(file_path, caption="π Slim Fit")
|
241 |
-
except Exception as e:
|
242 |
-
st.error(f"π¨ Camera snag: {str(e)}")
|
243 |
-
|
244 |
-
st.write("ποΈπ€‘ GIF Blast")
|
245 |
-
if st.button("π GIF It", key="imageio_3"):
|
246 |
-
# ποΈπ€‘ Makes GIFs like a circus juggler! | π₯ imageio.mimwrite("gif.gif", [f1, f2], fps=5) - Flips frames into fun!
|
247 |
-
try:
|
248 |
-
reader = imageio.get_reader('<video0>')
|
249 |
-
frames = [reader.get_next_data() for _ in range(10)]
|
250 |
-
file_path = f"imageio_gif_{datetime.now().strftime('%Y%m%d_%H%M%S')}.gif"
|
251 |
-
imageio.mimwrite(file_path, frames, fps=5)
|
252 |
-
save_to_history("ποΈ GIF", file_path)
|
253 |
-
st.image(file_path, caption="π€‘ GIF Party")
|
254 |
-
except Exception as e:
|
255 |
-
st.error(f"π¨ Camera snag: {str(e)}")
|
256 |
-
|
257 |
-
# 4. PyAV - π¬ AV rock fest!
|
258 |
-
with st.expander("4οΈβ£ π¬ PyAV Rave"):
|
259 |
-
st.write("π₯ AV King: FFmpeg-powered chaos!")
|
260 |
-
st.subheader("π₯ Top Tricks")
|
261 |
-
|
262 |
-
st.write("π₯π₯ Video Jam")
|
263 |
-
if st.button("π¬ Roll It", key="pyav_1"):
|
264 |
-
# π₯π₯ Captures like a rockstar shredding! | πΉ container = av.open('/dev/video0') - Rocks the cam like a live gig!
|
265 |
-
try:
|
266 |
-
container = av.open('/dev/video0')
|
267 |
-
stream = container.streams.video[0]
|
268 |
-
file_path = f"pyav_vid_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
269 |
-
output = av.open(file_path, 'w')
|
270 |
-
out_stream = output.add_stream('h264', rate=30)
|
271 |
-
for i, frame in enumerate(container.decode(stream)):
|
272 |
-
if i > 30: break
|
273 |
-
out_frame = frame.reformat(out_stream.width, out_stream.height)
|
274 |
-
output.mux(out_stream.encode(out_frame))
|
275 |
-
output.close()
|
276 |
-
container.close()
|
277 |
-
save_to_history("π₯ Video", file_path)
|
278 |
-
st.video(file_path)
|
279 |
-
except Exception as e:
|
280 |
-
st.error(f"π¨ Camera snag: {str(e)}")
|
281 |
-
|
282 |
-
st.write("π¬πΏ Audio Rip")
|
283 |
-
if st.button("π΅ Snag Sound", key="pyav_2"):
|
284 |
-
# π¬πΏ Pulls audio like a popcorn thief! | ποΈ frames = [f for f in av.open('vid.mp4').decode()] - Steals sound like a ninja!
|
285 |
-
try:
|
286 |
-
container = av.open('/dev/video0', 'r', format='v4l2')
|
287 |
-
file_path = f"pyav_audio_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
|
288 |
-
output = av.open(file_path, 'w')
|
289 |
-
out_stream = output.add_stream('pcm_s16le', rate=44100)
|
290 |
-
for packet in container.demux():
|
291 |
-
for frame in packet.decode():
|
292 |
-
if frame.is_corrupt: continue
|
293 |
-
if hasattr(frame, 'to_ndarray'):
|
294 |
-
output.mux(out_stream.encode(frame))
|
295 |
-
if os.path.getsize(file_path) > 100000: break
|
296 |
-
output.close()
|
297 |
-
container.close()
|
298 |
-
save_to_history("π΅ Audio", file_path)
|
299 |
-
st.audio(file_path)
|
300 |
-
except Exception as e:
|
301 |
-
st.error(f"π¨ Camera snag: {str(e)}")
|
302 |
-
|
303 |
-
st.write("π€β¨ Flip Snap")
|
304 |
-
if st.button("π Twist It", key="pyav_3"):
|
305 |
-
# π€β¨ Flips colors like a rebel teen! | π¨ graph = av.filter.Graph().add("negate").pull() - Inverts like a goth makeover!
|
306 |
-
try:
|
307 |
-
container = av.open('/dev/video0')
|
308 |
-
stream = container.streams.video[0]
|
309 |
-
file_path = f"pyav_filter_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
310 |
-
output = av.open(file_path, 'w')
|
311 |
-
out_stream = output.add_stream('h264', rate=30)
|
312 |
-
graph = av.filter.Graph()
|
313 |
-
filt = graph.add("negate")
|
314 |
-
for i, frame in enumerate(container.decode(stream)):
|
315 |
-
if i > 30: break
|
316 |
-
filt.push(frame)
|
317 |
-
out_frame = filt.pull()
|
318 |
-
output.mux(out_stream.encode(out_frame.reformat(out_stream.width, out_stream.height)))
|
319 |
-
output.close()
|
320 |
-
container.close()
|
321 |
-
save_to_history("π₯ Video", file_path)
|
322 |
-
st.video(file_path, caption="π€ Flip Vibes")
|
323 |
-
except Exception as e:
|
324 |
-
st.error(f"π¨ Camera snag: {str(e)}")
|
325 |
-
|
326 |
-
# 5. MoviePy - π₯ Editing extravaganza!
|
327 |
-
with st.expander("5οΈβ£ πΌ MoviePy Gala"):
|
328 |
-
st.write("π₯ Edit Queen: Video diva vibes!")
|
329 |
-
st.subheader("π₯ Top Tricks")
|
330 |
-
|
331 |
-
st.write("ποΈπ Frame Dance")
|
332 |
-
if st.button("π¬ Spin It", key="moviepy_1"):
|
333 |
-
# ποΈπ Twirls frames like a dance diva! | π₯ clip = mp.ImageSequenceClip([f1, f2], fps=15) - Makes vids like a pro choreographer!
|
334 |
-
cap = None
|
335 |
-
for i in range(10):
|
336 |
-
cap = cv2.VideoCapture(i)
|
337 |
-
if cap.isOpened():
|
338 |
-
break
|
339 |
-
cap.release()
|
340 |
-
if cap and cap.isOpened():
|
341 |
-
frames = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(30)]
|
342 |
-
cap.release()
|
343 |
-
file_path = f"moviepy_seq_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
344 |
-
clip = mp.ImageSequenceClip(frames, fps=15)
|
345 |
-
clip.write_videofile(file_path)
|
346 |
-
save_to_history("π₯ Video", file_path)
|
347 |
-
st.video(file_path)
|
348 |
-
else:
|
349 |
-
st.error("π¨ No camera found!")
|
350 |
-
|
351 |
-
st.write("ππ Size Snap")
|
352 |
-
if st.button("βοΈ Trim It", key="moviepy_2"):
|
353 |
-
# ππ Resizes like a royal tailor! | βοΈ clip = mp.VideoFileClip("vid.mp4").resize((320, 240)) - Fits vids like a bespoke suit!
|
354 |
-
cap = None
|
355 |
-
for i in range(10):
|
356 |
-
cap = cv2.VideoCapture(i)
|
357 |
-
if cap.isOpened():
|
358 |
-
break
|
359 |
-
cap.release()
|
360 |
-
if cap and cap.isOpened():
|
361 |
-
frames = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(30)]
|
362 |
-
cap.release()
|
363 |
-
temp_path = "temp.mp4"
|
364 |
-
mp.ImageSequenceClip(frames, fps=15).write_videofile(temp_path)
|
365 |
-
clip = mp.VideoFileClip(temp_path).resize((320, 240))
|
366 |
-
file_path = f"moviepy_resized_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
367 |
-
clip.write_videofile(file_path)
|
368 |
-
save_to_history("π₯ Video", file_path)
|
369 |
-
st.video(file_path, caption="π Tiny King")
|
370 |
-
else:
|
371 |
-
st.error("π¨ No camera found!")
|
372 |
-
|
373 |
-
st.write("π¬π€ Join Jam")
|
374 |
-
if st.button("π Link It", key="moviepy_3"):
|
375 |
-
# π¬π€ Stitches clips like a love guru! | π₯ final = mp.concatenate_videoclips([clip1, clip2]) - Hooks up vids like a matchmaker!
|
376 |
-
cap = None
|
377 |
-
for i in range(10):
|
378 |
-
cap = cv2.VideoCapture(i)
|
379 |
-
if cap.isOpened():
|
380 |
-
break
|
381 |
-
cap.release()
|
382 |
-
if cap and cap.isOpened():
|
383 |
-
frames1 = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(15)]
|
384 |
-
frames2 = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(15)]
|
385 |
-
cap.release()
|
386 |
-
clip1 = mp.ImageSequenceClip(frames1, fps=15)
|
387 |
-
clip2 = mp.ImageSequenceClip(frames2, fps=15)
|
388 |
-
final_clip = mp.concatenate_videoclips([clip1, clip2])
|
389 |
-
file_path = f"moviepy_concat_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
390 |
-
final_clip.write_videofile(file_path)
|
391 |
-
save_to_history("π₯ Video", file_path)
|
392 |
-
st.video(file_path, caption="π€ Duo Dance")
|
393 |
-
else:
|
394 |
-
st.error("π¨ No camera found!")
|
395 |
-
|
396 |
-
# 6. JS Audio - π΅ Browser beats!
|
397 |
-
with st.expander("6οΈβ£ π΅ JS Audio Jam"):
|
398 |
-
st.write("π Web Wizard: Browser-based sound sorcery!")
|
399 |
-
st.subheader("π₯ Top Tricks")
|
400 |
-
|
401 |
-
# π€π©οΈ Record audio with MediaRecorder
|
402 |
-
record_js = """
|
403 |
-
<div>
|
404 |
-
<button id="recordBtn" onclick="startRecording()">ποΈ Record</button>
|
405 |
-
<button id="stopBtn" onclick="stopRecording()" disabled>βΉοΈ Stop</button>
|
406 |
-
<audio id="audioPlayback" controls></audio>
|
407 |
-
</div>
|
408 |
-
<script>
|
409 |
-
let mediaRecorder;
|
410 |
-
let audioChunks = [];
|
411 |
-
navigator.mediaDevices.getUserMedia({ audio: true })
|
412 |
-
.then(stream => {
|
413 |
-
mediaRecorder = new MediaRecorder(stream);
|
414 |
-
mediaRecorder.ondataavailable = e => audioChunks.push(e.data);
|
415 |
-
mediaRecorder.onstop = () => {
|
416 |
-
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
417 |
-
const audioUrl = URL.createObjectURL(audioBlob);
|
418 |
-
document.getElementById('audioPlayback').src = audioUrl;
|
419 |
-
audioChunks = [];
|
420 |
-
};
|
421 |
-
});
|
422 |
-
function startRecording() {
|
423 |
-
mediaRecorder.start();
|
424 |
-
document.getElementById('recordBtn').disabled = true;
|
425 |
-
document.getElementById('stopBtn').disabled = false;
|
426 |
-
}
|
427 |
-
function stopRecording() {
|
428 |
-
mediaRecorder.stop();
|
429 |
-
document.getElementById('recordBtn').disabled = false;
|
430 |
-
document.getElementById('stopBtn').disabled = true;
|
431 |
-
}
|
432 |
-
</script>
|
433 |
-
"""
|
434 |
-
st.write("π€π©οΈ Mic Drop")
|
435 |
-
st.markdown(record_js, unsafe_allow_html=True)
|
436 |
-
|
437 |
-
# ππ‘ Play tone with Web Audio API
|
438 |
-
tone_js = """
|
439 |
-
<button onclick="playTone()">πΆ Beep!</button>
|
440 |
-
<script>
|
441 |
-
function playTone() {
|
442 |
-
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
443 |
-
const oscillator = audioCtx.createOscillator();
|
444 |
-
oscillator.type = 'sine';
|
445 |
-
oscillator.frequency.setValueAtTime(440, audioCtx.currentTime);
|
446 |
-
oscillator.connect(audioCtx.destination);
|
447 |
-
oscillator.start();
|
448 |
-
setTimeout(() => oscillator.stop(), 500);
|
449 |
-
}
|
450 |
-
</script>
|
451 |
-
"""
|
452 |
-
st.write("ππ‘ Tone Snap")
|
453 |
-
st.markdown(tone_js, unsafe_allow_html=True)
|
454 |
|
455 |
# π Upload zone like a media drop party!
|
456 |
st.header("π₯π Drop Zone")
|
457 |
-
uploaded_files = st.file_uploader("
|
458 |
if uploaded_files:
|
459 |
for uploaded_file in uploaded_files:
|
460 |
-
file_type = uploaded_file.type.split('/')[0]
|
461 |
file_path = f"uploaded_{uploaded_file.name}"
|
462 |
-
with open(file_path,
|
463 |
f.write(uploaded_file.read())
|
464 |
-
|
465 |
-
save_to_history(emoji_type, file_path)
|
466 |
|
467 |
-
#
|
468 |
-
st.header("πͺ
|
469 |
if st.session_state['file_history']:
|
470 |
images = [f for f in st.session_state['file_history'] if f['Type'] == "πΌοΈ Image"]
|
471 |
-
audios = [f for f in st.session_state['file_history'] if f['Type'] == "π΅ Audio"]
|
472 |
-
videos = [f for f in st.session_state['file_history'] if f['Type'] in ["π₯ Video", "ποΈ GIF"]]
|
473 |
-
|
474 |
if images:
|
475 |
st.subheader("πΌοΈ Pic Parade")
|
476 |
cols = st.columns(3)
|
477 |
for i, img in enumerate(images):
|
478 |
with cols[i % 3]:
|
479 |
st.image(img['Path'], caption=img['Path'], use_column_width=True)
|
480 |
-
|
481 |
-
if audios:
|
482 |
-
st.subheader("π΅ Sound Splash")
|
483 |
-
for audio in audios:
|
484 |
-
st.audio(audio['Path'], format=f"audio/{audio['Path'].split('.')[-1]}")
|
485 |
-
st.write(f"π€ {audio['Path']}")
|
486 |
-
|
487 |
-
if videos:
|
488 |
-
st.subheader("π₯ Vid Vortex")
|
489 |
-
for video in videos:
|
490 |
-
st.video(video['Path'])
|
491 |
-
st.write(f"π¬ {video['Path']}")
|
492 |
else:
|
493 |
-
st.write("π« No
|
494 |
|
495 |
# π History log like a time machine!
|
496 |
st.header("β³ Snap Saga")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
4 |
import os
|
|
|
|
|
5 |
import threading
|
6 |
import time
|
7 |
+
from PIL import Image
|
8 |
+
from io import BytesIO
|
9 |
+
import aiofiles
|
10 |
+
import asyncio
|
11 |
+
import base64
|
12 |
|
13 |
# ππ₯ Initialize session state like a galactic DJ spinning tracks!
|
14 |
if 'file_history' not in st.session_state:
|
15 |
st.session_state['file_history'] = []
|
16 |
+
if 'auto_capture_running' not_in st.session_state:
|
|
|
|
|
|
|
|
|
17 |
st.session_state['auto_capture_running'] = False
|
18 |
+
if 'cam_file' not_in st.session_state:
|
19 |
+
st.session_state['cam_file'] = None
|
20 |
|
21 |
+
# ππΎ Save to history like a time-traveling scribe! | π
β¨ save_to_history("πΌοΈ Image", "pic.jpg") - Stamps a pic in the history books like a boss!
|
22 |
def save_to_history(file_type, file_path):
|
23 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
24 |
st.session_state['file_history'].append({
|
|
|
29 |
|
30 |
# πΈβ° Auto-capture every 10 secs like a sneaky shutterbug!
|
31 |
def auto_capture():
|
32 |
+
if st.session_state['auto_capture_running'] and 'cam_img' in st.session_state:
|
33 |
+
cam_img = st.session_state['cam_img']
|
34 |
+
if cam_img:
|
35 |
+
filename = f"auto_snap_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
36 |
+
with open(filename, "wb") as f:
|
37 |
+
f.write(cam_img.getvalue())
|
38 |
+
save_to_history("πΌοΈ Image", filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
threading.Timer(10, auto_capture).start()
|
40 |
|
41 |
# ποΈ Sidebar config like a spaceship control panel!
|
42 |
with st.sidebar:
|
43 |
+
st.header("ποΈπΈ Snap Shack")
|
|
|
|
|
|
|
44 |
if st.button("β° Start Auto-Snap"):
|
45 |
st.session_state['auto_capture_running'] = True
|
46 |
auto_capture()
|
47 |
if st.button("βΉοΈ Stop Auto-Snap"):
|
48 |
st.session_state['auto_capture_running'] = False
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
# π Sidebar file outline with emoji flair!
|
51 |
+
st.subheader("π Snap Stash")
|
52 |
if st.session_state['file_history']:
|
53 |
images = [f for f in st.session_state['file_history'] if f['Type'] == "πΌοΈ Image"]
|
|
|
|
|
54 |
if images:
|
55 |
st.write("πΌοΈ Images")
|
56 |
for img in images:
|
57 |
st.write(f"- {img['Path']} @ {img['Timestamp']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
else:
|
59 |
+
st.write("π³οΈ Empty Stash!")
|
60 |
|
61 |
# ππ¨ Main UI kicks off like a cosmic art show!
|
62 |
+
st.title("πΈ Snap Craze")
|
63 |
+
|
64 |
+
# πΈπ· Camera snap zone!
|
65 |
+
st.header("πΈπ₯ Snap Zone")
|
66 |
+
cam_img = st.camera_input("π· Snap It!", key="cam")
|
67 |
+
if cam_img:
|
68 |
+
filename = f"cam_snap_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
69 |
+
if st.session_state['cam_file'] and os.path.exists(st.session_state['cam_file']):
|
70 |
+
os.remove(st.session_state['cam_file'])
|
71 |
+
with open(filename, "wb") as f:
|
72 |
+
f.write(cam_img.getvalue())
|
73 |
+
st.session_state['cam_file'] = filename
|
74 |
+
st.session_state['cam_img'] = cam_img # Store for auto-capture
|
75 |
+
save_to_history("πΌοΈ Image", filename)
|
76 |
+
st.image(Image.open(filename), caption="Latest Snap", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
# π Upload zone like a media drop party!
|
79 |
st.header("π₯π Drop Zone")
|
80 |
+
uploaded_files = st.file_uploader("πΈ Toss Pics", accept_multiple_files=True, type=['jpg', 'png'])
|
81 |
if uploaded_files:
|
82 |
for uploaded_file in uploaded_files:
|
|
|
83 |
file_path = f"uploaded_{uploaded_file.name}"
|
84 |
+
with open(file_path, "wb") as f:
|
85 |
f.write(uploaded_file.read())
|
86 |
+
save_to_history("πΌοΈ Image", file_path)
|
|
|
87 |
|
88 |
+
# πΌοΈ Gallery like a media circus!
|
89 |
+
st.header("πͺ Snap Show")
|
90 |
if st.session_state['file_history']:
|
91 |
images = [f for f in st.session_state['file_history'] if f['Type'] == "πΌοΈ Image"]
|
|
|
|
|
|
|
92 |
if images:
|
93 |
st.subheader("πΌοΈ Pic Parade")
|
94 |
cols = st.columns(3)
|
95 |
for i, img in enumerate(images):
|
96 |
with cols[i % 3]:
|
97 |
st.image(img['Path'], caption=img['Path'], use_column_width=True)
|
98 |
+
st.markdown(f'<a href="data:image/jpeg;base64,{base64.b64encode(open(img["Path"], "rb").read()).decode()}" download="{os.path.basename(img["Path"])}">π₯ Snag It!</a>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
else:
|
100 |
+
st.write("π« No snaps yet!")
|
101 |
|
102 |
# π History log like a time machine!
|
103 |
st.header("β³ Snap Saga")
|