Doobdeedoo commited on
Commit
c150709
·
verified ·
1 Parent(s): 059aee9

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +435 -19
  3. prompts.txt +6 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Doobidoo
3
- emoji: 📈
4
- colorFrom: red
5
- colorTo: gray
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: doobidoo
3
+ emoji: 🐳
4
+ colorFrom: yellow
5
+ colorTo: green
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,435 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Webcam Brightness Meter</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .brightness-meter {
11
+ background: linear-gradient(90deg, #000000 0%, #333333 20%, #666666 40%, #999999 60%, #cccccc 80%, #ffffff 100%);
12
+ }
13
+ .brightness-indicator {
14
+ transition: left 0.3s ease;
15
+ }
16
+ .pulse {
17
+ animation: pulse 2s infinite;
18
+ }
19
+ @keyframes pulse {
20
+ 0% {
21
+ box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
22
+ }
23
+ 70% {
24
+ box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
25
+ }
26
+ 100% {
27
+ box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
28
+ }
29
+ }
30
+ #chart-container {
31
+ height: 200px;
32
+ width: 100%;
33
+ position: relative;
34
+ }
35
+ #historyChart {
36
+ width: 100% !important;
37
+ height: 200px !important;
38
+ }
39
+ </style>
40
+ </head>
41
+ <body class="bg-gray-900 text-white min-h-screen">
42
+ <div class="container mx-auto px-4 py-8">
43
+ <header class="text-center mb-8">
44
+ <h1 class="text-4xl font-bold mb-2">Webcam Brightness Meter</h1>
45
+ <p class="text-gray-400">Measure ambient light levels using your webcam</p>
46
+ </header>
47
+
48
+ <main class="max-w-4xl mx-auto">
49
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg mb-8">
50
+ <div class="flex flex-col md:flex-row gap-6">
51
+ <div class="w-full md:w-1/2">
52
+ <div class="relative aspect-video bg-black rounded-lg overflow-hidden mb-4">
53
+ <video id="webcam" autoplay playsinline class="w-full h-full object-cover"></video>
54
+ <div id="overlay" class="absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center">
55
+ <div class="text-center p-4">
56
+ <i class="fas fa-camera text-4xl mb-2"></i>
57
+ <p>Webcam access required</p>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ <div class="flex justify-center gap-4">
62
+ <button id="startBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center gap-2">
63
+ <i class="fas fa-play"></i> Start
64
+ </button>
65
+ <button id="stopBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg flex items-center gap-2" disabled>
66
+ <i class="fas fa-stop"></i> Stop
67
+ </button>
68
+ </div>
69
+ </div>
70
+
71
+ <div class="w-full md:w-1/2">
72
+ <div class="bg-gray-700 p-4 rounded-lg h-full">
73
+ <h2 class="text-xl font-semibold mb-4">Brightness Analysis</h2>
74
+
75
+ <div class="mb-6">
76
+ <div class="flex justify-between mb-2">
77
+ <span>0%</span>
78
+ <span id="brightnessValue" class="text-xl font-bold">--</span>
79
+ <span>100%</span>
80
+ </div>
81
+ <div class="brightness-meter h-4 rounded-full relative">
82
+ <div id="brightnessIndicator" class="brightness-indicator absolute top-0 -ml-2 -mt-2 w-4 h-8 bg-white rounded-full shadow-lg"></div>
83
+ </div>
84
+ </div>
85
+
86
+ <div class="grid grid-cols-2 gap-4">
87
+ <div class="bg-gray-600 p-3 rounded-lg">
88
+ <div class="text-sm text-gray-300 mb-1">Light Level</div>
89
+ <div id="lightLevel" class="text-2xl font-bold">--</div>
90
+ </div>
91
+ <div class="bg-gray-600 p-3 rounded-lg">
92
+ <div class="text-sm text-gray-300 mb-1">Status</div>
93
+ <div id="lightStatus" class="text-2xl font-bold">Inactive</div>
94
+ </div>
95
+ </div>
96
+
97
+ <div class="mt-6 bg-gray-600 p-3 rounded-lg">
98
+ <div class="text-sm text-gray-300 mb-1">Tips</div>
99
+ <ul class="text-sm list-disc pl-5 space-y-1">
100
+ <li>Point your webcam at the area you want to measure</li>
101
+ <li>For best results, avoid direct light sources in frame</li>
102
+ <li>Values update every second</li>
103
+ </ul>
104
+ </div>
105
+ </div>
106
+ </div>
107
+ </div>
108
+ </div>
109
+
110
+ <div class="bg-gray-800 rounded-xl p-6 shadow-lg">
111
+ <h2 class="text-xl font-semibold mb-4">Brightness History</h2>
112
+ <div id="chart-container">
113
+ <canvas id="historyChart"></canvas>
114
+ </div>
115
+ </div>
116
+ </main>
117
+ </div>
118
+
119
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
120
+ <script>
121
+ // DOM Elements
122
+ const video = document.getElementById('webcam');
123
+ const overlay = document.getElementById('overlay');
124
+ const startBtn = document.getElementById('startBtn');
125
+ const stopBtn = document.getElementById('stopBtn');
126
+ const brightnessValue = document.getElementById('brightnessValue');
127
+ const brightnessIndicator = document.getElementById('brightnessIndicator');
128
+ const lightLevel = document.getElementById('lightLevel');
129
+ const lightStatus = document.getElementById('lightStatus');
130
+
131
+ // Variables
132
+ let stream = null;
133
+ let interval = null;
134
+ let brightnessHistory = [];
135
+ const maxHistory = 30; // Keep last 30 readings
136
+ let chart = null;
137
+ let isVideoReady = false;
138
+
139
+ // Initialize Chart
140
+ function initChart() {
141
+ const ctx = document.getElementById('historyChart').getContext('2d');
142
+ chart = new Chart(ctx, {
143
+ type: 'line',
144
+ data: {
145
+ labels: Array(maxHistory).fill(''),
146
+ datasets: [{
147
+ label: 'Brightness',
148
+ data: brightnessHistory,
149
+ borderColor: 'rgb(59, 130, 246)',
150
+ backgroundColor: 'rgba(59, 130, 246, 0.1)',
151
+ tension: 0.3,
152
+ fill: true,
153
+ pointRadius: 0 // Remove points for cleaner look
154
+ }]
155
+ },
156
+ options: {
157
+ responsive: true,
158
+ maintainAspectRatio: false,
159
+ animation: {
160
+ duration: 0 // Disable animation to prevent chart resizing
161
+ },
162
+ scales: {
163
+ y: {
164
+ min: 0,
165
+ max: 100,
166
+ ticks: {
167
+ callback: function(value) {
168
+ return value + '%';
169
+ }
170
+ }
171
+ },
172
+ x: {
173
+ display: false // Hide x-axis labels
174
+ }
175
+ },
176
+ plugins: {
177
+ legend: {
178
+ display: false
179
+ },
180
+ tooltip: {
181
+ callbacks: {
182
+ label: function(context) {
183
+ return 'Brightness: ' + context.parsed.y.toFixed(1) + '%';
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ });
190
+ }
191
+
192
+ // Update Chart
193
+ function updateChart() {
194
+ if (chart) {
195
+ chart.data.datasets[0].data = brightnessHistory;
196
+ chart.update('none'); // Update without animation
197
+ }
198
+ }
199
+
200
+ // Calculate brightness from video frame
201
+ function calculateBrightness() {
202
+ if (!isVideoReady || video.videoWidth === 0 || video.videoHeight === 0) {
203
+ throw new Error('Video not ready for measurement');
204
+ }
205
+
206
+ const canvas = document.createElement('canvas');
207
+ canvas.width = video.videoWidth;
208
+ canvas.height = video.videoHeight;
209
+ const ctx = canvas.getContext('2d');
210
+
211
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
212
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
213
+ const data = imageData.data;
214
+
215
+ let brightnessSum = 0;
216
+ const pixelCount = data.length / 4;
217
+
218
+ for (let i = 0; i < data.length; i += 4) {
219
+ // Calculate perceived brightness (weighted average of RGB)
220
+ const r = data[i];
221
+ const g = data[i + 1];
222
+ const b = data[i + 2];
223
+ const brightness = 0.299 * r + 0.587 * g + 0.114 * b;
224
+ brightnessSum += brightness;
225
+ }
226
+
227
+ const avgBrightness = (brightnessSum / pixelCount) / 2.55; // Convert 0-255 to 0-100
228
+ return Math.round(avgBrightness * 10) / 10; // Round to 1 decimal place
229
+ }
230
+
231
+ // Update UI with brightness value
232
+ function updateBrightnessUI(brightness) {
233
+ brightnessValue.textContent = `${brightness}%`;
234
+ brightnessIndicator.style.left = `${brightness}%`;
235
+
236
+ // Update light level description
237
+ lightLevel.textContent = `${brightness}%`;
238
+
239
+ // Update status based on brightness
240
+ let status = '';
241
+ let statusColor = '';
242
+
243
+ if (brightness < 20) {
244
+ status = 'Very Dark';
245
+ statusColor = 'text-purple-400';
246
+ } else if (brightness < 40) {
247
+ status = 'Dark';
248
+ statusColor = 'text-blue-400';
249
+ } else if (brightness < 60) {
250
+ status = 'Moderate';
251
+ statusColor = 'text-green-400';
252
+ } else if (brightness < 80) {
253
+ status = 'Bright';
254
+ statusColor = 'text-yellow-400';
255
+ } else {
256
+ status = 'Very Bright';
257
+ statusColor = 'text-red-400';
258
+ }
259
+
260
+ lightStatus.textContent = status;
261
+ lightStatus.className = `text-2xl font-bold ${statusColor}`;
262
+
263
+ // Add to history
264
+ brightnessHistory.push(brightness);
265
+ if (brightnessHistory.length > maxHistory) {
266
+ brightnessHistory.shift();
267
+ }
268
+
269
+ updateChart();
270
+ }
271
+
272
+ // Start measuring brightness
273
+ async function startMeasuring() {
274
+ try {
275
+ // First stop any existing measurements
276
+ if (interval) {
277
+ clearInterval(interval);
278
+ interval = null;
279
+ }
280
+
281
+ // Initialize webcam if not already active
282
+ if (!stream) {
283
+ await initWebcam();
284
+ }
285
+
286
+ // Wait for video to be ready
287
+ if (!isVideoReady) {
288
+ await new Promise((resolve) => {
289
+ const checkReady = () => {
290
+ if (video.videoWidth > 0 && video.videoHeight > 0) {
291
+ isVideoReady = true;
292
+ resolve();
293
+ } else {
294
+ setTimeout(checkReady, 100);
295
+ }
296
+ };
297
+ checkReady();
298
+ });
299
+ }
300
+
301
+ overlay.classList.add('hidden');
302
+ startBtn.disabled = true;
303
+ stopBtn.disabled = false;
304
+
305
+ // Initial reading
306
+ const brightness = calculateBrightness();
307
+ updateBrightnessUI(brightness);
308
+
309
+ // Set up interval for continuous readings
310
+ interval = setInterval(() => {
311
+ try {
312
+ const brightness = calculateBrightness();
313
+ updateBrightnessUI(brightness);
314
+ } catch (err) {
315
+ console.error('Error during measurement:', err);
316
+ // Try to recover by stopping and showing error
317
+ stopMeasuring();
318
+ overlay.classList.remove('hidden');
319
+ overlay.innerHTML = `
320
+ <div class="text-center p-4">
321
+ <i class="fas fa-exclamation-triangle text-4xl mb-2 text-red-500"></i>
322
+ <p>Measurement error</p>
323
+ <p class="text-sm text-gray-300 mt-2">${err.message}</p>
324
+ <button id="retryBtn" class="mt-4 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg">
325
+ <i class="fas fa-sync-alt mr-2"></i> Try Again
326
+ </button>
327
+ </div>
328
+ `;
329
+ document.getElementById('retryBtn').addEventListener('click', startMeasuring);
330
+ }
331
+ }, 1000);
332
+ } catch (err) {
333
+ console.error('Error starting measurements:', err);
334
+ overlay.classList.remove('hidden');
335
+ overlay.innerHTML = `
336
+ <div class="text-center p-4">
337
+ <i class="fas fa-exclamation-triangle text-4xl mb-2 text-red-500"></i>
338
+ <p>Error starting measurements</p>
339
+ <p class="text-sm text-gray-300 mt-2">${err.message}</p>
340
+ <button id="retryBtn" class="mt-4 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg">
341
+ <i class="fas fa-sync-alt mr-2"></i> Try Again
342
+ </button>
343
+ </div>
344
+ `;
345
+ document.getElementById('retryBtn').addEventListener('click', startMeasuring);
346
+ }
347
+ }
348
+
349
+ // Stop measuring brightness and release webcam
350
+ function stopMeasuring() {
351
+ clearInterval(interval);
352
+ interval = null;
353
+ startBtn.disabled = false;
354
+ stopBtn.disabled = true;
355
+ overlay.classList.remove('hidden');
356
+
357
+ // Release webcam resources
358
+ if (stream) {
359
+ stream.getTracks().forEach(track => track.stop());
360
+ video.srcObject = null;
361
+ stream = null;
362
+ isVideoReady = false;
363
+ }
364
+
365
+ // Reset UI values
366
+ brightnessValue.textContent = '--';
367
+ brightnessIndicator.style.left = '0%';
368
+ lightLevel.textContent = '--';
369
+ lightStatus.textContent = 'Inactive';
370
+ lightStatus.className = 'text-2xl font-bold';
371
+ }
372
+
373
+ // Initialize webcam
374
+ async function initWebcam() {
375
+ try {
376
+ // Stop any existing stream first
377
+ if (stream) {
378
+ stream.getTracks().forEach(track => track.stop());
379
+ }
380
+
381
+ stream = await navigator.mediaDevices.getUserMedia({ video: true });
382
+ video.srcObject = stream;
383
+ isVideoReady = false;
384
+
385
+ // Wait for video metadata to load
386
+ await new Promise((resolve) => {
387
+ video.onloadedmetadata = () => {
388
+ isVideoReady = true;
389
+ resolve();
390
+ };
391
+ });
392
+
393
+ // Initialize chart if not already done
394
+ if (!chart) {
395
+ initChart();
396
+ }
397
+
398
+ return true;
399
+ } catch (err) {
400
+ console.error('Error accessing webcam:', err);
401
+ overlay.classList.remove('hidden');
402
+ overlay.innerHTML = `
403
+ <div class="text-center p-4">
404
+ <i class="fas fa-exclamation-triangle text-4xl mb-2 text-red-500"></i>
405
+ <p>Could not access webcam</p>
406
+ <p class="text-sm text-gray-300 mt-2">${err.message}</p>
407
+ <button id="retryBtn" class="mt-4 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg">
408
+ <i class="fas fa-sync-alt mr-2"></i> Try Again
409
+ </button>
410
+ </div>
411
+ `;
412
+ document.getElementById('retryBtn').addEventListener('click', initWebcam);
413
+ return false;
414
+ }
415
+ }
416
+
417
+ // Event Listeners
418
+ startBtn.addEventListener('click', startMeasuring);
419
+ stopBtn.addEventListener('click', stopMeasuring);
420
+
421
+ // Clean up on page unload
422
+ window.addEventListener('beforeunload', () => {
423
+ if (stream) {
424
+ stream.getTracks().forEach(track => track.stop());
425
+ }
426
+ if (interval) {
427
+ clearInterval(interval);
428
+ }
429
+ });
430
+
431
+ // Initialize chart on load
432
+ document.addEventListener('DOMContentLoaded', initChart);
433
+ </script>
434
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Doobdeedoo/doobidoo" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
435
+ </html>
prompts.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ build an app that can measure the brighness of my surrendings using any webcam
2
+ please reduce the height of the Brightness History to a reasonable amount similar to the upper div mb-8
3
+ as soon as the webcam starts measuring, the brightness graph grows in size which is odd and not wanted, it should be fixed in size
4
+ the webcam should also be released, when mesurements stops
5
+ stopping works but I have to refresh the site to make the start button do its thing
6
+ Now I have this error : Error starting measurements Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0. when pressing the start buttonm