awacke1 commited on
Commit
e42a810
Β·
verified Β·
1 Parent(s): b65f4e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +307 -165
app.py CHANGED
@@ -1,173 +1,315 @@
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 base64
10
- from imutils.video import VideoStream
11
- import cv2
12
- from pydub import AudioSegment
13
- from pydub.playback import play
14
- import pypdf
15
- import numpy as np
16
 
17
- # 🌟πŸ”₯ Initialize session state
18
- if 'file_history' not in st.session_state:
19
- st.session_state['file_history'] = []
20
- if 'auto_capture_running' not in st.session_state:
21
- st.session_state['auto_capture_running'] = False
22
 
23
- # πŸ“œπŸ’Ύ Save to history
24
- def save_to_history(file_type, file_path, data=None):
25
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
26
- if file_type == "πŸ–ΌοΈ Image" and data is not None:
27
- cv2.imwrite(file_path, cv2.cvtColor(data, cv2.COLOR_RGB2BGR))
28
- elif file_type == "🎡 Audio" and data is not None:
29
- data.export(file_path, format="wav")
30
- elif file_type == "πŸ“œ PDF" and data is not None:
31
- with open(file_path, "wb") as f:
32
- f.write(data)
33
- st.session_state['file_history'].append({
34
- "Timestamp": timestamp,
35
- "Type": file_type,
36
- "Path": file_path
37
- })
38
 
39
- # πŸ“Έβ° Auto-capture every 10 secs
40
- def auto_capture(streams):
41
- while st.session_state['auto_capture_running']:
42
- for i, stream in enumerate(streams):
43
- frame = stream.read()
44
- if frame is not None:
45
- filename = f"cam{i}_auto_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
46
- save_to_history("πŸ–ΌοΈ Image", filename, frame)
47
- time.sleep(10)
48
-
49
- # πŸŽ›οΈ Sidebar config
50
- with st.sidebar:
51
- st.header("πŸŽšοΈπŸ“Έ Snap Shack")
52
- streams = [
53
- VideoStream(src=0).start(), # Camera 0
54
- VideoStream(src=1).start() # Camera 1
55
- ]
56
- if st.button("⏰ Start Auto-Snap"):
57
- st.session_state['auto_capture_running'] = True
58
- threading.Thread(target=auto_capture, args=(streams,), daemon=True).start()
59
- if st.button("⏹️ Stop Auto-Snap"):
60
- st.session_state['auto_capture_running'] = False
61
-
62
- # Audio recording control
63
- if st.button("πŸŽ™οΈ Record Audio (5s)"):
64
- audio = AudioSegment.silent(duration=5000) # Placeholder; real mic capture needs pyaudio
65
- filename = f"audio_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
66
- save_to_history("🎡 Audio", filename, audio)
67
-
68
- st.subheader("πŸ“œ Snap Stash")
69
- if st.session_state['file_history']:
70
- images = [f for f in st.session_state['file_history'] if f['Type'] == "πŸ–ΌοΈ Image"]
71
- audios = [f for f in st.session_state['file_history'] if f['Type'] == "🎡 Audio"]
72
- pdfs = [f for f in st.session_state['file_history'] if f['Type'] == "πŸ“œ PDF"]
73
- if images:
74
- st.write("πŸ–ΌοΈ Images")
75
- for img in images:
76
- st.write(f"- {img['Path']} @ {img['Timestamp']}")
77
- if audios:
78
- st.write("🎡 Audios")
79
- for aud in audios:
80
- st.write(f"- {aud['Path']} @ {aud['Timestamp']}")
81
- if pdfs:
82
- st.write("πŸ“œ PDFs")
83
- for pdf in pdfs:
84
- st.write(f"- {pdf['Path']} @ {pdf['Timestamp']}")
85
- else:
86
- st.write("πŸ•³οΈ Empty Stash!")
87
-
88
- # 🌍🎨 Main UI
89
- st.title("πŸ“Έ Multi-Lib Snap Craze")
90
-
91
- # πŸ“ΈπŸ“· Camera snap zone
92
- st.header("πŸ“ΈπŸŽ₯ Snap Zone")
93
- cols = st.columns(2)
94
- placeholders = [cols[0].empty(), cols[1].empty()]
95
- for i, (placeholder, stream) in enumerate(zip(placeholders, streams)):
96
- frame = stream.read()
97
- if frame is not None:
98
- placeholder.image(frame, caption=f"Live Cam {i}", use_container_width=True)
99
- else:
100
- placeholder.error(f"🚨 No feed from Cam {i}")
101
-
102
- if st.button(f"πŸ“Έ Snap Cam {i}", key=f"snap{i}"):
103
- frame = stream.read()
104
- if frame is not None:
105
- filename = f"cam{i}_snap_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
106
- save_to_history("πŸ–ΌοΈ Image", filename, frame)
107
-
108
- # πŸ“‚ Upload zone (PDFs and Images)
109
- st.header("πŸ“₯πŸŽ‰ Drop Zone")
110
- uploaded_files = st.file_uploader("πŸ“œπŸ“Έ Upload PDFs or Images", accept_multiple_files=True, type=['pdf', 'jpg', 'png'])
111
- if uploaded_files:
112
- for uploaded_file in uploaded_files:
113
- file_type = "πŸ“œ PDF" if uploaded_file.type == "application/pdf" else "πŸ–ΌοΈ Image"
114
- file_path = f"uploaded_{uploaded_file.name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.{uploaded_file.name.split('.')[-1]}"
115
- if file_type == "πŸ–ΌοΈ Image":
116
- img = Image.open(uploaded_file)
117
- img_array = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
118
- save_to_history(file_type, file_path, img_array)
119
- st.image(img, caption=uploaded_file.name, use_container_width=True)
120
- else:
121
- save_to_history(file_type, file_path, uploaded_file.getvalue())
122
- with pypdf.PdfReader(uploaded_file) as reader:
123
- st.write(f"PDF Pages: {len(reader.pages)}")
124
 
125
- # πŸ–ΌοΈ Gallery
126
- st.header("πŸŽͺ Snap Show")
127
- if st.session_state['file_history']:
128
- images = [f for f in st.session_state['file_history'] if f['Type'] == "πŸ–ΌοΈ Image"]
129
- audios = [f for f in st.session_state['file_history'] if f['Type'] == "🎡 Audio"]
130
- pdfs = [f for f in st.session_state['file_history'] if f['Type'] == "πŸ“œ PDF"]
131
- if images:
132
- st.subheader("πŸ–ΌοΈ Pic Parade")
133
- cols = st.columns(3)
134
- for i, img in enumerate(images):
135
- with cols[i % 3]:
136
- if os.path.exists(img['Path']):
137
- st.image(img['Path'], caption=img['Path'], use_container_width=True)
138
- with open(img['Path'], "rb") as f:
139
- img_data = f.read()
140
- st.markdown(f'<a href="data:image/jpeg;base64,{base64.b64encode(img_data).decode()}" download="{os.path.basename(img["Path"])}">πŸ“₯ Snag It!</a>', unsafe_allow_html=True)
141
- if audios:
142
- st.subheader("🎡 Audio Alley")
143
- for aud in audios:
144
- if os.path.exists(aud['Path']):
145
- st.audio(aud['Path'])
146
- with open(aud['Path'], "rb") as f:
147
- aud_data = f.read()
148
- st.markdown(f'<a href="data:audio/wav;base64,{base64.b64encode(aud_data).decode()}" download="{os.path.basename(aud["Path"])}">πŸ“₯ Snag It!</a>', unsafe_allow_html=True)
149
- if pdfs:
150
- st.subheader("πŸ“œ PDF Plaza")
151
- for pdf in pdfs:
152
- if os.path.exists(pdf['Path']):
153
- with open(pdf['Path'], "rb") as f:
154
- pdf_data = f.read()
155
- st.markdown(f'<a href="data:application/pdf;base64,{base64.b64encode(pdf_data).decode()}" download="{os.path.basename(pdf["Path"])}">πŸ“₯ Download {os.path.basename(pdf["Path"])}</a>', unsafe_allow_html=True)
156
- else:
157
- st.write("🚫 No snaps yet!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
- # πŸ“œ History log
160
- st.header("⏳ Snap Saga")
161
- if st.session_state['file_history']:
162
- df = pd.DataFrame(st.session_state['file_history'])
163
- st.dataframe(df)
164
- else:
165
- st.write("πŸ•³οΈ Nothing snapped yet!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
- # Cleanup
168
- def cleanup():
169
- for stream in streams:
170
- stream.stop()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
- import atexit
173
- atexit.register(cleanup)
 
 
 
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ # 🌟πŸ”₯ Set up the Streamlit UI with a checklist style!
4
+ st.title("πŸ“‹ Library Demo Checklist")
5
+ st.write("Check off each demo as you try these witty one-liners from our galaxy of libraries!")
 
 
6
 
7
+ # 🌟 Session state to track checklist
8
+ if 'checklist' not in st.session_state:
9
+ st.session_state['checklist'] = {i: False for i in range(1, 41)} # 40 demos total
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ # πŸ“œ PDF Libraries Section
12
+ with st.expander("πŸ“œ PDF Libraries", expanded=True):
13
+ st.subheader("PDF Powerhouse")
14
+ st.write("Tick these off as you shred, spin, and weave PDFs!")
15
+
16
+ # 1. pypdf
17
+ st.checkbox("1. pypdf - Snags text faster than a paper shredder at a spy convention!",
18
+ key="check_1",
19
+ value=st.session_state['checklist'][1],
20
+ on_change=lambda: st.session_state['checklist'].update({1: not st.session_state['checklist'][1]}))
21
+ st.code("pypdf.PdfReader('doc.pdf').pages[0].extract_text()")
22
+
23
+ # 2. pikepdf
24
+ st.checkbox("2. pikepdf - Gives your PDF a makeover like a digital plastic surgeon!",
25
+ key="check_2",
26
+ value=st.session_state['checklist'][2],
27
+ on_change=lambda: st.session_state['checklist'].update({2: not st.session_state['checklist'][2]}))
28
+ st.code("pikepdf.Pdf.open('in.pdf').save('out.pdf')")
29
+
30
+ # 3. pdfminer.six
31
+ st.checkbox("3. pdfminer.six - Pulls text out like a magician yanking a rabbit from a hat!",
32
+ key="check_3",
33
+ value=st.session_state['checklist'][3],
34
+ on_change=lambda: st.session_state['checklist'].update({3: not st.session_state['checklist'][3]}))
35
+ st.code("pdfminer.high_level.extract_text('doc.pdf')")
36
+
37
+ # 4. fpdf2
38
+ st.checkbox("4. fpdf2 - Whips up a PDF quicker than a chef flipping pancakes!",
39
+ key="check_4",
40
+ value=st.session_state['checklist'][4],
41
+ on_change=lambda: st.session_state['checklist'].update({4: not st.session_state['checklist'][4]}))
42
+ st.code("fpdf.FPDF().add_page().output('new.pdf')")
43
+
44
+ # 5. pdfkit
45
+ st.checkbox("5. pdfkit - Turns web pages into PDFs like a spider spinning a paper web!",
46
+ key="check_5",
47
+ value=st.session_state['checklist'][5],
48
+ on_change=lambda: st.session_state['checklist'].update({5: not st.session_state['checklist'][5]}))
49
+ st.code("pdfkit.from_url('http://example.com', 'out.pdf')")
50
+
51
+ # 6. pdfrw
52
+ st.checkbox("6. pdfrw - Reads PDFs like a librarian with a caffeine buzz!",
53
+ key="check_6",
54
+ value=st.session_state['checklist'][6],
55
+ on_change=lambda: st.session_state['checklist'].update({6: not st.session_state['checklist'][6]}))
56
+ st.code("pdfrw.PdfReader('doc.pdf')")
57
+
58
+ # 7. pdfplumber
59
+ st.checkbox("7. pdfplumber - Dives into PDFs and grabs text like a plumber fixing a leaky pipe!",
60
+ key="check_7",
61
+ value=st.session_state['checklist'][7],
62
+ on_change=lambda: st.session_state['checklist'].update({7: not st.session_state['checklist'][7]}))
63
+ st.code("pdfplumber.open('doc.pdf').pages[0].extract_text()")
64
+
65
+ # 8. pymupdf
66
+ st.checkbox("8. pymupdf - Speed-reads PDFs faster than a bookworm on espresso!",
67
+ key="check_8",
68
+ value=st.session_state['checklist'][8],
69
+ on_change=lambda: st.session_state['checklist'].update({8: not st.session_state['checklist'][8]}))
70
+ st.code("fitz.open('doc.pdf')[0].get_text()")
71
+
72
+ # 9. borb
73
+ st.checkbox("9. borb - Crafts PDFs smoother than a bard reciting poetry!",
74
+ key="check_9",
75
+ value=st.session_state['checklist'][9],
76
+ on_change=lambda: st.session_state['checklist'].update({9: not st.session_state['checklist'][9]}))
77
+ st.code("borb.pdf.Document().save('out.pdf')")
78
+
79
+ # 10. pdf2image
80
+ st.checkbox("10. pdf2image - Turns PDFs into pics like a wizard waving a wand!",
81
+ key="check_10",
82
+ value=st.session_state['checklist'][10],
83
+ on_change=lambda: st.session_state['checklist'].update({10: not st.session_state['checklist'][10]}))
84
+ st.code("pdf2image.convert_from_path('doc.pdf')[0].save('out.jpg')")
 
 
 
 
 
 
 
 
 
 
 
85
 
86
+ # πŸ“Έ Image Capture Libraries Section
87
+ with st.expander("πŸ“Έ Image Capture Libraries", expanded=True):
88
+ st.subheader("Image Snappers")
89
+ st.write("Check these off as you snap, grab, and process pixel perfection!")
90
+
91
+ # 11. opencv-python
92
+ st.checkbox("11. opencv-python - Snaps a pic quicker than a paparazzi at a celebrity meltdown!",
93
+ key="check_11",
94
+ value=st.session_state['checklist'][11],
95
+ on_change=lambda: st.session_state['checklist'].update({11: not st.session_state['checklist'][11]}))
96
+ st.code("cv2.imwrite('snap.jpg', cv2.VideoCapture(0).read()[1])")
97
+
98
+ # 12. pillow
99
+ st.checkbox("12. pillow - Polishes pics like a pillow fluffer at a sleepover!",
100
+ key="check_12",
101
+ value=st.session_state['checklist'][12],
102
+ on_change=lambda: st.session_state['checklist'].update({12: not st.session_state['checklist'][12]}))
103
+ st.code("Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).save('out.jpg')")
104
+
105
+ # 13. imutils
106
+ st.checkbox("13. imutils - Grabs frames smoother than a cat burglar in sneakers!",
107
+ key="check_13",
108
+ value=st.session_state['checklist'][13],
109
+ on_change=lambda: st.session_state['checklist'].update({13: not st.session_state['checklist'][13]}))
110
+ st.code("imutils.video.VideoStream(src=0).start().read()")
111
+
112
+ # 14. pyscreeze
113
+ st.checkbox("14. pyscreeze - Snags your screen like a sneaky spy with a camera!",
114
+ key="check_14",
115
+ value=st.session_state['checklist'][14],
116
+ on_change=lambda: st.session_state['checklist'].update({14: not st.session_state['checklist'][14]}))
117
+ st.code("pyscreeze.screenshot().save('screen.jpg')")
118
+
119
+ # 15. pyautogui
120
+ st.checkbox("15. pyautogui - Snaps your desktop faster than a robot paparazzo!",
121
+ key="check_15",
122
+ value=st.session_state['checklist'][15],
123
+ on_change=lambda: st.session_state['checklist'].update({15: not st.session_state['checklist'][15]}))
124
+ st.code("pyautogui.screenshot().save('screen.jpg')")
125
+
126
+ # 16. mss
127
+ st.checkbox("16. mss - Captures screens quicker than a ninja snapping selfies!",
128
+ key="check_16",
129
+ value=st.session_state['checklist'][16],
130
+ on_change=lambda: st.session_state['checklist'].update({16: not st.session_state['checklist'][16]}))
131
+ st.code("mss.mss().shot(output='screen.png')")
132
+
133
+ # 17. imageio
134
+ st.checkbox("17. imageio - Snags images like a pirate looting a pixel treasure chest!",
135
+ key="check_17",
136
+ value=st.session_state['checklist'][17],
137
+ on_change=lambda: st.session_state['checklist'].update({17: not st.session_state['checklist'][17]}))
138
+ st.code("imageio.imwrite('out.jpg', imageio.get_reader('<video0>').get_next_data())")
139
+
140
+ # 18. pygrabber
141
+ st.checkbox("18. pygrabber - Grabs Windows shots like a cowboy roping a pixel steer!",
142
+ key="check_18",
143
+ value=st.session_state['checklist'][18],
144
+ on_change=lambda: st.session_state['checklist'].update({18: not st.session_state['checklist'][18]}))
145
+ st.code("pygrabber.dshow_graph.FilterGraph().grab_frame().save('out.jpg')")
146
+
147
+ # 19. scikit-image
148
+ st.checkbox("19. scikit-image - Processes pics like a scientist dissecting a pixel frog!",
149
+ key="check_19",
150
+ value=st.session_state['checklist'][19],
151
+ on_change=lambda: st.session_state['checklist'].update({19: not st.session_state['checklist'][19]}))
152
+ st.code("skimage.io.imsave('out.jpg', frame)")
153
+
154
+ # 20. grab
155
+ st.checkbox("20. grab - Snaps screens like a ghost haunting your desktop!",
156
+ key="check_20",
157
+ value=st.session_state['checklist'][20],
158
+ on_change=lambda: st.session_state['checklist'].update({20: not st.session_state['checklist'][20]}))
159
+ st.code("grab.Grab().screen().save('screen.jpg')")
160
 
161
+ # πŸŽ₯ Video Capture Libraries Section
162
+ with st.expander("πŸŽ₯ Video Capture Libraries", expanded=True):
163
+ st.subheader("Video Vanguards")
164
+ st.write("Mark these as you snatch frames and stream like a pro!")
165
+
166
+ # 21. opencv-python (Video)
167
+ st.checkbox("21. opencv-python - Grabs video frames like a director snatching scenes from a blockbuster!",
168
+ key="check_21",
169
+ value=st.session_state['checklist'][21],
170
+ on_change=lambda: st.session_state['checklist'].update({21: not st.session_state['checklist'][21]}))
171
+ st.code("cv2.VideoCapture(0).read()[1]")
172
+
173
+ # 22. vidgear
174
+ st.checkbox("22. vidgear - Streams video smoother than a greased-up eel!",
175
+ key="check_22",
176
+ value=st.session_state['checklist'][22],
177
+ on_change=lambda: st.session_state['checklist'].update({22: not st.session_state['checklist'][22]}))
178
+ st.code("vidgear.gears.CamGear(source=0).start().read()")
179
+
180
+ # 23. moviepy
181
+ st.checkbox("23. moviepy - Edits clips like a director yelling 'Cut!' at a pixel party!",
182
+ key="check_23",
183
+ value=st.session_state['checklist'][23],
184
+ on_change=lambda: st.session_state['checklist'].update({23: not st.session_state['checklist'][23]}))
185
+ st.code("moviepy.editor.VideoFileClip('video.mp4').write_videofile('out.mp4')")
186
+
187
+ # 24. pyav
188
+ st.checkbox("24. pyav - Grabs frames like a ninja snatching scrolls from a vault!",
189
+ key="check_24",
190
+ value=st.session_state['checklist'][24],
191
+ on_change=lambda: st.session_state['checklist'].update({24: not st.session_state['checklist'][24]}))
192
+ st.code("av.open('/dev/video0').decode(video=0).__next__()")
193
+
194
+ # 25. pafy
195
+ st.checkbox("25. pafy - Streams YouTube like a couch potato binge-watching cat videos!",
196
+ key="check_25",
197
+ value=st.session_state['checklist'][25],
198
+ on_change=lambda: st.session_state['checklist'].update({25: not st.session_state['checklist'][25]}))
199
+ st.code("pafy.new('youtube_url').getbest().url")
200
+
201
+ # 26. cvpubsubs
202
+ st.checkbox("26. cvpubsubs - Captures cams like a pub serving pixel pints!",
203
+ key="check_26",
204
+ value=st.session_state['checklist'][26],
205
+ on_change=lambda: st.session_state['checklist'].update({26: not st.session_state['checklist'][26]}))
206
+ st.code("cvpubsubs.webcam_pub.VideoHandlerThread(0).start()")
207
+
208
+ # 27. imutils (Video)
209
+ st.checkbox("27. imutils - Streams video like a thief sneaking frames in the night!",
210
+ key="check_27",
211
+ value=st.session_state['checklist'][27],
212
+ on_change=lambda: st.session_state['checklist'].update({27: not st.session_state['checklist'][27]}))
213
+ st.code("imutils.video.VideoStream(src=0).start().read()")
214
+
215
+ # 28. imageio (Video)
216
+ st.checkbox("28. imageio - Snags video frames like a fisherman reeling in pixel fish!",
217
+ key="check_28",
218
+ value=st.session_state['checklist'][28],
219
+ on_change=lambda: st.session_state['checklist'].update({28: not st.session_state['checklist'][28]}))
220
+ st.code("imageio.get_reader('<video0>').get_next_data()")
221
+
222
+ # 29. grab (Video)
223
+ st.checkbox("29. grab - Records screens like a ghost filming a desktop haunting!",
224
+ key="check_29",
225
+ value=st.session_state['checklist'][29],
226
+ on_change=lambda: st.session_state['checklist'].update({29: not st.session_state['checklist'][29]}))
227
+ st.code("grab.Grab().screen().save('frame.jpg')")
228
+
229
+ # 30. pyscreeze (Video)
230
+ st.checkbox("30. pyscreeze - Snaps screen video like a spy with a frame-by-frame camera!",
231
+ key="check_30",
232
+ value=st.session_state['checklist'][30],
233
+ on_change=lambda: st.session_state['checklist'].update({30: not st.session_state['checklist'][30]}))
234
+ st.code("pyscreeze.screenshot().save('screen.jpg')")
235
 
236
+ # 🎡 Audio Capture Libraries Section
237
+ with st.expander("🎡 Audio Capture Libraries", expanded=True):
238
+ st.subheader("Audio Aces")
239
+ st.write("Tune in and check these off as you capture sound like a pro!")
240
+
241
+ # 31. pydub
242
+ st.checkbox("31. pydub - Twists audio like a DJ spinning tunes at a silent disco!",
243
+ key="check_31",
244
+ value=st.session_state['checklist'][31],
245
+ on_change=lambda: st.session_state['checklist'].update({31: not st.session_state['checklist'][31]}))
246
+ st.code("pydub.AudioSegment.from_file('audio.wav').export('out.wav')")
247
+
248
+ # 32. pyaudio
249
+ st.checkbox("32. pyaudio - Grabs sound bites faster than a parrot snagging crackers!",
250
+ key="check_32",
251
+ value=st.session_state['checklist'][32],
252
+ on_change=lambda: st.session_state['checklist'].update({32: not st.session_state['checklist'][32]}))
253
+ st.code("pyaudio.PyAudio().open().read(1024)")
254
+
255
+ # 33. sounddevice
256
+ st.checkbox("33. sounddevice - Snags audio smoother than a whisper in a quiet cave!",
257
+ key="check_33",
258
+ value=st.session_state['checklist'][33],
259
+ on_change=lambda: st.session_state['checklist'].update({33: not st.session_state['checklist'][33]}))
260
+ st.code("sounddevice.rec(44100).tobytes()")
261
+
262
+ # 34. soundfile
263
+ st.checkbox("34. soundfile - Saves sound like a librarian archiving whispers!",
264
+ key="check_34",
265
+ value=st.session_state['checklist'][34],
266
+ on_change=lambda: st.session_state['checklist'].update({34: not st.session_state['checklist'][34]}))
267
+ st.code("soundfile.write('out.wav', data, 44100)")
268
+
269
+ # 35. pyaudioanalysis
270
+ st.checkbox("35. pyaudioanalysis - Analyzes audio like a detective cracking a sonic mystery!",
271
+ key="check_35",
272
+ value=st.session_state['checklist'][35],
273
+ on_change=lambda: st.session_state['checklist'].update({35: not st.session_state['checklist'][35]}))
274
+ st.code("pyAudioAnalysis.audioBasicIO.read_audio_file('audio.wav')[1]")
275
+
276
+ # 36. pyo
277
+ st.checkbox("36. pyo - Spins audio magic like a wizard mixing potions!",
278
+ key="check_36",
279
+ value=st.session_state['checklist'][36],
280
+ on_change=lambda: st.session_state['checklist'].update({36: not st.session_state['checklist'][36]}))
281
+ st.code("pyo.Server().boot().start()")
282
+
283
+ # 37. speechrecognition
284
+ st.checkbox("37. speechrecognition - Hears you like a nosy neighbor with super ears!",
285
+ key="check_37",
286
+ value=st.session_state['checklist'][37],
287
+ on_change=lambda: st.session_state['checklist'].update({37: not st.session_state['checklist'][37]}))
288
+ st.code("speech_recognition.Recognizer().listen(speech_recognition.Microphone())")
289
+
290
+ # 38. pyalsaaudio
291
+ st.checkbox("38. pyalsaaudio - Grabs Linux sound like a penguin snagging fish!",
292
+ key="check_38",
293
+ value=st.session_state['checklist'][38],
294
+ on_change=lambda: st.session_state['checklist'].update({38: not st.session_state['checklist'][38]}))
295
+ st.code("pyalsa.alsaaudio.PCM().read()[1]")
296
+
297
+ # 39. soundcard
298
+ st.checkbox("39. soundcard - Captures sound like a bard strumming a silent lute!",
299
+ key="check_39",
300
+ value=st.session_state['checklist'][39],
301
+ on_change=lambda: st.session_state['checklist'].update({39: not st.session_state['checklist'][39]}))
302
+ st.code("soundcard.default_microphone().record(44100, 1)")
303
+
304
+ # 40. webrtcvad
305
+ st.checkbox("40. webrtcvad - Detects voices like a spy eavesdropping on a whisper party!",
306
+ key="check_40",
307
+ value=st.session_state['checklist'][40],
308
+ on_change=lambda: st.session_state['checklist'].update({40: not st.session_state['checklist'][40]}))
309
+ st.code("webrtcvad.Vad().is_speech(audio_frame, 16000)")
310
 
311
+ # πŸ“Š Progress Tracker
312
+ st.write("### Progress Tracker")
313
+ completed = sum(1 for v in st.session_state['checklist'].values() if v)
314
+ st.progress(completed / 40)
315
+ st.write(f"{completed} out of 40 demos checked off!")