Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,301 +1,213 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
# ๐๐ฅ Set up the Streamlit UI with
|
4 |
-
st.title("
|
5 |
-
st.write("
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
|
87 |
-
with
|
88 |
-
|
89 |
-
|
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 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
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 |
-
|
237 |
-
|
238 |
-
|
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. sounddevice
|
249 |
-
st.checkbox("32. sounddevice - Snags audio smoother than a whisper in a quiet cave!",
|
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("sounddevice.rec(44100).tobytes()")
|
254 |
-
|
255 |
-
# 33. soundfile
|
256 |
-
st.checkbox("33. soundfile - Saves sound like a librarian archiving whispers!",
|
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("soundfile.write('out.wav', data, 44100)")
|
261 |
-
|
262 |
-
# 34. pyaudioanalysis
|
263 |
-
st.checkbox("34. pyaudioanalysis - Analyzes audio like a detective cracking a sonic mystery!",
|
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("pyAudioAnalysis.audioBasicIO.read_audio_file('audio.wav')[1]")
|
268 |
-
|
269 |
-
# 35. pyo
|
270 |
-
st.checkbox("35. pyo - Spins audio magic like a wizard mixing potions!",
|
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("pyo.Server().boot().start()")
|
275 |
-
|
276 |
-
# 36. speechrecognition
|
277 |
-
st.checkbox("36. speechrecognition - Hears you like a nosy neighbor with super ears!",
|
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("speech_recognition.Recognizer().listen(speech_recognition.Microphone())")
|
282 |
-
|
283 |
-
# 37. soundcard
|
284 |
-
st.checkbox("37. soundcard - Captures sound like a bard strumming a silent lute!",
|
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("soundcard.default_microphone().record(44100, 1)")
|
289 |
-
|
290 |
-
# 38. webrtcvad
|
291 |
-
st.checkbox("38. webrtcvad - Detects voices like a spy eavesdropping on a whisper party!",
|
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("webrtcvad.Vad().is_speech(audio_frame, 16000)")
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime
|
4 |
+
import os
|
5 |
+
import cv2
|
6 |
+
from PIL import Image
|
7 |
+
import numpy as np
|
8 |
+
from imutils.video import VideoStream
|
9 |
+
import pypdf
|
10 |
+
import pikepdf
|
11 |
+
import pdfminer.high_level
|
12 |
+
import fpdf
|
13 |
+
import pdfkit
|
14 |
+
import pdfplumber
|
15 |
+
import fitz # pymupdf
|
16 |
+
import borb.pdf
|
17 |
+
import pdf2image
|
18 |
+
import vidgear.gears
|
19 |
+
import moviepy.editor
|
20 |
+
import av
|
21 |
+
import pydub
|
22 |
+
import sounddevice as sd
|
23 |
+
import soundfile as sf
|
24 |
|
25 |
+
# ๐๐ฅ Set up the Streamlit UI with an impressive demo style!
|
26 |
+
st.title("๐ Impressive Library Demo Extravaganza")
|
27 |
+
st.write("Watch these libraries flex their muscles with live demos producing real outputs!")
|
28 |
|
29 |
+
# ๐ Demo Functions
|
30 |
+
def demo_pypdf():
|
31 |
+
with open("demo.pdf", "w") as f:
|
32 |
+
f.write("Hello from pypdf!")
|
33 |
+
reader = pypdf.PdfReader("demo.pdf")
|
34 |
+
return reader.pages[0].extract_text() if reader.pages else "No text found!"
|
35 |
|
36 |
+
def demo_pikepdf():
|
37 |
+
pdf = pikepdf.Pdf.new()
|
38 |
+
pdf.pages.append(pikepdf.Page(pikepdf.Dictionary()))
|
39 |
+
pdf.save("demo_pikepdf.pdf")
|
40 |
+
return "demo_pikepdf.pdf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
def demo_pdfminer():
|
43 |
+
with open("demo.pdf", "w") as f:
|
44 |
+
f.write("PDFminer magic!")
|
45 |
+
text = pdfminer.high_level.extract_text("demo.pdf")
|
46 |
+
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
def demo_fpdf():
|
49 |
+
pdf = fpdf.FPDF()
|
50 |
+
pdf.add_page()
|
51 |
+
pdf.set_font("Arial", size=12)
|
52 |
+
pdf.cell(200, 10, txt="FPDF rocks!", ln=True)
|
53 |
+
pdf.output("demo_fpdf.pdf")
|
54 |
+
return "demo_fpdf.pdf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
def demo_pdfkit():
|
57 |
+
pdfkit.from_string("<h1>Hello PDFkit!</h1>", "demo_pdfkit.pdf")
|
58 |
+
return "demo_pdfkit.pdf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
def demo_pdfplumber():
|
61 |
+
with open("demo.pdf", "w") as f:
|
62 |
+
f.write("Plumb this text!")
|
63 |
+
with pdfplumber.open("demo.pdf") as pdf:
|
64 |
+
return pdf.pages[0].extract_text() if pdf.pages else "No text!"
|
65 |
+
|
66 |
+
def demo_pymupdf():
|
67 |
+
doc = fitz.open()
|
68 |
+
page = doc.new_page()
|
69 |
+
page.insert_text((100, 100), "Pymupdf shines!")
|
70 |
+
doc.save("demo_pymupdf.pdf")
|
71 |
+
return "demo_pymupdf.pdf"
|
72 |
+
|
73 |
+
def demo_borb():
|
74 |
+
doc = borb.pdf.Document()
|
75 |
+
page = borb.pdf.Page()
|
76 |
+
doc.append_page(page)
|
77 |
+
doc.save("demo_borb.pdf")
|
78 |
+
return "demo_borb.pdf"
|
79 |
+
|
80 |
+
def demo_pdf2image():
|
81 |
+
with open("demo.pdf", "w") as f:
|
82 |
+
f.write("Image this!")
|
83 |
+
images = pdf2image.convert_from_path("demo.pdf")
|
84 |
+
images[0].save("demo_pdf2image.jpg")
|
85 |
+
return "demo_pdf2image.jpg"
|
86 |
+
|
87 |
+
def demo_opencv_image():
|
88 |
+
cap = cv2.VideoCapture(0)
|
89 |
+
ret, frame = cap.read()
|
90 |
+
if ret:
|
91 |
+
cv2.imwrite("demo_opencv.jpg", frame)
|
92 |
+
cap.release()
|
93 |
+
return "demo_opencv.jpg"
|
94 |
+
cap.release()
|
95 |
+
return None
|
96 |
+
|
97 |
+
def demo_imutils():
|
98 |
+
vs = VideoStream(src=0).start()
|
99 |
+
frame = vs.read()
|
100 |
+
vs.stop()
|
101 |
+
if frame is not None:
|
102 |
+
cv2.imwrite("demo_imutils.jpg", cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
|
103 |
+
return "demo_imutils.jpg"
|
104 |
+
return None
|
105 |
+
|
106 |
+
def demo_vidgear():
|
107 |
+
stream = vidgear.gears.CamGear(source=0).start()
|
108 |
+
frame = stream.read()
|
109 |
+
stream.stop()
|
110 |
+
if frame is not None:
|
111 |
+
cv2.imwrite("demo_vidgear.jpg", frame)
|
112 |
+
return "demo_vidgear.jpg"
|
113 |
+
return None
|
114 |
+
|
115 |
+
def demo_sounddevice():
|
116 |
+
audio = sd.rec(int(2 * 44100), samplerate=44100, channels=1)
|
117 |
+
sd.wait()
|
118 |
+
sf.write("demo_sounddevice.wav", audio, 44100)
|
119 |
+
return "demo_sounddevice.wav"
|
120 |
+
|
121 |
+
# ๐ Main Demo Interface
|
122 |
+
st.sidebar.header("๐ฎ Demo Controls")
|
123 |
+
demo_type = st.sidebar.selectbox("Choose a Demo Category", ["PDF", "Image Capture", "Video Capture", "Audio Capture"])
|
124 |
+
|
125 |
+
# ๐ PDF Demos
|
126 |
+
if demo_type == "PDF":
|
127 |
+
st.subheader("๐ PDF Powerhouse")
|
128 |
+
demo = st.selectbox("Pick a PDF Demo", [
|
129 |
+
"pypdf", "pikepdf", "pdfminer.six", "fpdf2", "pdfkit",
|
130 |
+
"pdfplumber", "pymupdf", "borb", "pdf2image"
|
131 |
+
])
|
132 |
+
if st.button("Run PDF Demo"):
|
133 |
+
with st.spinner("Running demo..."):
|
134 |
+
if demo == "pypdf":
|
135 |
+
result = demo_pypdf()
|
136 |
+
st.write("Extracted Text:", result)
|
137 |
+
elif demo == "pikepdf":
|
138 |
+
result = demo_pikepdf()
|
139 |
+
st.download_button("Download PDF", open(result, "rb").read(), file_name=result)
|
140 |
+
elif demo == "pdfminer.six":
|
141 |
+
result = demo_pdfminer()
|
142 |
+
st.write("Extracted Text:", result)
|
143 |
+
elif demo == "fpdf2":
|
144 |
+
result = demo_fpdf()
|
145 |
+
st.download_button("Download PDF", open(result, "rb").read(), file_name=result)
|
146 |
+
elif demo == "pdfkit":
|
147 |
+
result = demo_pdfkit()
|
148 |
+
st.download_button("Download PDF", open(result, "rb").read(), file_name=result)
|
149 |
+
elif demo == "pdfplumber":
|
150 |
+
result = demo_pdfplumber()
|
151 |
+
st.write("Extracted Text:", result)
|
152 |
+
elif demo == "pymupdf":
|
153 |
+
result = demo_pymupdf()
|
154 |
+
st.download_button("Download PDF", open(result, "rb").read(), file_name=result)
|
155 |
+
elif demo == "borb":
|
156 |
+
result = demo_borb()
|
157 |
+
st.download_button("Download PDF", open(result, "rb").read(), file_name=result)
|
158 |
+
elif demo == "pdf2image":
|
159 |
+
result = demo_pdf2image()
|
160 |
+
st.image(result, caption="Converted PDF to Image")
|
161 |
+
|
162 |
+
# ๐ธ Image Capture Demos
|
163 |
+
elif demo_type == "Image Capture":
|
164 |
+
st.subheader("๐ธ Image Snappers")
|
165 |
+
demo = st.selectbox("Pick an Image Demo", ["opencv-python", "imutils"])
|
166 |
+
if st.button("Run Image Demo"):
|
167 |
+
with st.spinner("Capturing image..."):
|
168 |
+
if demo == "opencv-python":
|
169 |
+
result = demo_opencv_image()
|
170 |
+
if result:
|
171 |
+
st.image(result, caption="Snapped with OpenCV!")
|
172 |
+
else:
|
173 |
+
st.error("Camera not detected!")
|
174 |
+
elif demo == "imutils":
|
175 |
+
result = demo_imutils()
|
176 |
+
if result:
|
177 |
+
st.image(result, caption="Snapped with Imutils!")
|
178 |
+
else:
|
179 |
+
st.error("Camera not detected!")
|
180 |
+
|
181 |
+
# ๐ฅ Video Capture Demos
|
182 |
+
elif demo_type == "Video Capture":
|
183 |
+
st.subheader("๐ฅ Video Vanguards")
|
184 |
+
demo = st.selectbox("Pick a Video Demo", ["opencv-python", "vidgear"])
|
185 |
+
if st.button("Run Video Demo"):
|
186 |
+
with st.spinner("Capturing video frame..."):
|
187 |
+
if demo == "opencv-python":
|
188 |
+
result = demo_opencv_image() # Using image capture as a proxy
|
189 |
+
if result:
|
190 |
+
st.image(result, caption="Frame from OpenCV Video!")
|
191 |
+
else:
|
192 |
+
st.error("Camera not detected!")
|
193 |
+
elif demo == "vidgear":
|
194 |
+
result = demo_vidgear()
|
195 |
+
if result:
|
196 |
+
st.image(result, caption="Frame from VidGear Video!")
|
197 |
+
else:
|
198 |
+
st.error("Camera not detected!")
|
199 |
+
|
200 |
+
# ๐ต Audio Capture Demos
|
201 |
+
elif demo_type == "Audio Capture":
|
202 |
+
st.subheader("๐ต Audio Aces")
|
203 |
+
demo = st.selectbox("Pick an Audio Demo", ["sounddevice"])
|
204 |
+
if st.button("Run Audio Demo"):
|
205 |
+
with st.spinner("Recording audio (2 seconds)..."):
|
206 |
+
if demo == "sounddevice":
|
207 |
+
result = demo_sounddevice()
|
208 |
+
st.audio(result, format="audio/wav")
|
209 |
+
st.download_button("Download Audio", open(result, "rb").read(), file_name=result)
|
210 |
+
|
211 |
+
# ๐ Results Display
|
212 |
+
st.write("### Results")
|
213 |
+
st.write("Check out your impressive outputs above!")
|