Rilaba commited on
Commit
eb5f874
·
verified ·
1 Parent(s): 4afdb5a

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +464 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Splitting Cake
3
- emoji: 📉
4
- colorFrom: gray
5
- colorTo: indigo
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: splitting-cake
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,464 @@
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>Cake Split - Proportional Division</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
+ .cake-piece {
11
+ transition: all 0.3s ease;
12
+ }
13
+ .cake-piece:hover {
14
+ transform: scale(1.05);
15
+ z-index: 10;
16
+ }
17
+ #cakeCanvas {
18
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
19
+ }
20
+ #cameraView {
21
+ transform: scaleX(-1); /* Mirror effect for front camera */
22
+ }
23
+ .slice-control {
24
+ -webkit-appearance: none;
25
+ height: 8px;
26
+ border-radius: 4px;
27
+ background: linear-gradient(90deg, #f59e0b, #ef4444);
28
+ }
29
+ .slice-control::-webkit-slider-thumb {
30
+ -webkit-appearance: none;
31
+ width: 20px;
32
+ height: 20px;
33
+ border-radius: 50%;
34
+ background: #3b82f6;
35
+ cursor: pointer;
36
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
37
+ }
38
+ </style>
39
+ </head>
40
+ <body class="bg-amber-50 min-h-screen">
41
+ <div class="container mx-auto px-4 py-8">
42
+ <header class="text-center mb-8">
43
+ <h1 class="text-4xl font-bold text-amber-800 mb-2">
44
+ <i class="fas fa-cake-candles mr-2"></i>Cake Split
45
+ </h1>
46
+ <p class="text-amber-600">Capture your cake and divide it proportionally</p>
47
+ </header>
48
+
49
+ <div class="flex flex-col lg:flex-row gap-8">
50
+ <!-- Camera Section -->
51
+ <div class="flex-1 bg-white rounded-xl shadow-lg p-6">
52
+ <div class="flex justify-between items-center mb-4">
53
+ <h2 class="text-xl font-semibold text-amber-800">
54
+ <i class="fas fa-camera mr-2"></i>Capture Your Cake
55
+ </h2>
56
+ <div class="flex gap-2">
57
+ <button id="switchCamera" class="bg-amber-100 text-amber-800 p-2 rounded-full">
58
+ <i class="fas fa-camera-retro"></i>
59
+ </button>
60
+ <button id="flashToggle" class="bg-amber-100 text-amber-800 p-2 rounded-full">
61
+ <i class="fas fa-bolt"></i>
62
+ </button>
63
+ </div>
64
+ </div>
65
+
66
+ <div class="relative aspect-square bg-gray-200 rounded-lg overflow-hidden mb-4">
67
+ <video id="cameraView" autoplay playsinline class="w-full h-full object-cover"></video>
68
+ <div id="cameraOverlay" class="absolute inset-0 flex items-center justify-center hidden">
69
+ <div class="cake-overlay-circle w-64 h-64 rounded-full border-4 border-dashed border-white opacity-70"></div>
70
+ </div>
71
+ </div>
72
+
73
+ <div class="flex justify-center gap-4">
74
+ <button id="captureBtn" class="bg-amber-600 hover:bg-amber-700 text-white px-6 py-3 rounded-full font-medium flex items-center">
75
+ <i class="fas fa-camera mr-2"></i> Capture Cake
76
+ </button>
77
+ <button id="uploadBtn" class="bg-amber-100 hover:bg-amber-200 text-amber-800 px-6 py-3 rounded-full font-medium flex items-center">
78
+ <i class="fas fa-upload mr-2"></i> Upload
79
+ </button>
80
+ <input type="file" id="fileInput" accept="image/*" class="hidden">
81
+ </div>
82
+ </div>
83
+
84
+ <!-- Division Section -->
85
+ <div class="flex-1 bg-white rounded-xl shadow-lg p-6">
86
+ <h2 class="text-xl font-semibold text-amber-800 mb-4">
87
+ <i class="fas fa-divide mr-2"></i>Divide Proportionally
88
+ </h2>
89
+
90
+ <div class="mb-6">
91
+ <label class="block text-amber-700 mb-2">Number of People</label>
92
+ <div class="flex items-center gap-4">
93
+ <button id="decrementPeople" class="bg-amber-100 text-amber-800 w-10 h-10 rounded-full flex items-center justify-center">
94
+ <i class="fas fa-minus"></i>
95
+ </button>
96
+ <span id="peopleCount" class="text-2xl font-bold text-amber-800 min-w-[40px] text-center">4</span>
97
+ <button id="incrementPeople" class="bg-amber-100 text-amber-800 w-10 h-10 rounded-full flex items-center justify-center">
98
+ <i class="fas fa-plus"></i>
99
+ </button>
100
+ </div>
101
+ </div>
102
+
103
+ <div class="mb-6">
104
+ <label class="block text-amber-700 mb-2">Slice Proportions</label>
105
+ <div id="proportionControls" class="space-y-4">
106
+ <!-- Dynamic controls will be added here -->
107
+ </div>
108
+ </div>
109
+
110
+ <div class="flex justify-center mb-6">
111
+ <button id="divideBtn" class="bg-amber-600 hover:bg-amber-700 text-white px-6 py-3 rounded-full font-medium flex items-center">
112
+ <i class="fas fa-cut mr-2"></i> Divide Cake
113
+ </button>
114
+ </div>
115
+
116
+ <div class="aspect-square bg-gray-100 rounded-lg overflow-hidden flex items-center justify-center relative">
117
+ <canvas id="cakeCanvas" class="max-w-full max-h-full"></canvas>
118
+ <div id="noCakeMessage" class="absolute inset-0 flex items-center justify-center text-gray-400">
119
+ <div class="text-center">
120
+ <i class="fas fa-cake-candles text-4xl mb-2"></i>
121
+ <p>Capture or upload a cake image</p>
122
+ </div>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ </div>
127
+
128
+ <!-- Results Section (hidden by default) -->
129
+ <div id="resultsSection" class="mt-8 bg-white rounded-xl shadow-lg p-6 hidden">
130
+ <h2 class="text-xl font-semibold text-amber-800 mb-4">
131
+ <i class="fas fa-chart-pie mr-2"></i>Division Results
132
+ </h2>
133
+
134
+ <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
135
+ <!-- Dynamic results will be added here -->
136
+ </div>
137
+
138
+ <div class="flex justify-center gap-4">
139
+ <button id="saveBtn" class="bg-amber-600 hover:bg-amber-700 text-white px-6 py-3 rounded-full font-medium flex items-center">
140
+ <i class="fas fa-save mr-2"></i> Save Division
141
+ </button>
142
+ <button id="shareBtn" class="bg-amber-100 hover:bg-amber-200 text-amber-800 px-6 py-3 rounded-full font-medium flex items-center">
143
+ <i class="fas fa-share-alt mr-2"></i> Share
144
+ </button>
145
+ </div>
146
+ </div>
147
+ </div>
148
+
149
+ <script>
150
+ // DOM Elements
151
+ const cameraView = document.getElementById('cameraView');
152
+ const cameraOverlay = document.getElementById('cameraOverlay');
153
+ const captureBtn = document.getElementById('captureBtn');
154
+ const uploadBtn = document.getElementById('uploadBtn');
155
+ const fileInput = document.getElementById('fileInput');
156
+ const cakeCanvas = document.getElementById('cakeCanvas');
157
+ const ctx = cakeCanvas.getContext('2d');
158
+ const noCakeMessage = document.getElementById('noCakeMessage');
159
+ const peopleCount = document.getElementById('peopleCount');
160
+ const incrementPeople = document.getElementById('incrementPeople');
161
+ const decrementPeople = document.getElementById('decrementPeople');
162
+ const proportionControls = document.getElementById('proportionControls');
163
+ const divideBtn = document.getElementById('divideBtn');
164
+ const resultsSection = document.getElementById('resultsSection');
165
+ const switchCamera = document.getElementById('switchCamera');
166
+ const flashToggle = document.getElementById('flashToggle');
167
+
168
+ // App State
169
+ let currentImage = null;
170
+ let people = 4;
171
+ let proportions = Array(people).fill(1);
172
+ let stream = null;
173
+ let facingMode = "user"; // front camera by default
174
+ let flashOn = false;
175
+
176
+ // Initialize
177
+ setupProportionControls();
178
+ setupCamera();
179
+ resizeCanvas();
180
+
181
+ // Event Listeners
182
+ window.addEventListener('resize', resizeCanvas);
183
+ captureBtn.addEventListener('click', captureCake);
184
+ uploadBtn.addEventListener('click', () => fileInput.click());
185
+ fileInput.addEventListener('change', handleFileUpload);
186
+ incrementPeople.addEventListener('click', () => updatePeopleCount(1));
187
+ decrementPeople.addEventListener('click', () => updatePeopleCount(-1));
188
+ divideBtn.addEventListener('click', divideCake);
189
+ switchCamera.addEventListener('click', toggleCamera);
190
+ flashToggle.addEventListener('click', toggleFlash);
191
+
192
+ // Functions
193
+ function setupCamera() {
194
+ const constraints = {
195
+ video: {
196
+ facingMode: facingMode,
197
+ width: { ideal: 1280 },
198
+ height: { ideal: 1280 }
199
+ }
200
+ };
201
+
202
+ navigator.mediaDevices.getUserMedia(constraints)
203
+ .then(function(mediaStream) {
204
+ stream = mediaStream;
205
+ cameraView.srcObject = stream;
206
+ cameraOverlay.classList.remove('hidden');
207
+ })
208
+ .catch(function(err) {
209
+ console.error("Camera error: ", err);
210
+ alert("Could not access the camera. Please check permissions.");
211
+ });
212
+ }
213
+
214
+ function toggleCamera() {
215
+ if (stream) {
216
+ stream.getTracks().forEach(track => track.stop());
217
+ }
218
+ facingMode = facingMode === "user" ? "environment" : "user";
219
+ setupCamera();
220
+ }
221
+
222
+ function toggleFlash() {
223
+ flashOn = !flashOn;
224
+ flashToggle.classList.toggle('bg-amber-600', flashOn);
225
+ flashToggle.classList.toggle('text-white', flashOn);
226
+
227
+ if (stream) {
228
+ const videoTrack = stream.getVideoTracks()[0];
229
+ if (videoTrack && videoTrack.getCapabilities().torch) {
230
+ videoTrack.applyConstraints({
231
+ advanced: [{torch: flashOn}]
232
+ }).catch(err => console.error("Flash error:", err));
233
+ }
234
+ }
235
+ }
236
+
237
+ function captureCake() {
238
+ if (!stream) return;
239
+
240
+ // Temporarily hide overlay for capture
241
+ cameraOverlay.classList.add('hidden');
242
+
243
+ // Create temporary canvas to capture the video frame
244
+ const tempCanvas = document.createElement('canvas');
245
+ tempCanvas.width = cameraView.videoWidth;
246
+ tempCanvas.height = cameraView.videoHeight;
247
+ const tempCtx = tempCanvas.getContext('2d');
248
+ tempCtx.drawImage(cameraView, 0, 0, tempCanvas.width, tempCanvas.height);
249
+
250
+ // Restore overlay
251
+ cameraOverlay.classList.remove('hidden');
252
+
253
+ // Process the captured image
254
+ processImage(tempCanvas.toDataURL('image/jpeg'));
255
+ }
256
+
257
+ function handleFileUpload(e) {
258
+ const file = e.target.files[0];
259
+ if (!file) return;
260
+
261
+ const reader = new FileReader();
262
+ reader.onload = function(event) {
263
+ processImage(event.target.result);
264
+ };
265
+ reader.readAsDataURL(file);
266
+ }
267
+
268
+ function processImage(imageData) {
269
+ currentImage = new Image();
270
+ currentImage.onload = function() {
271
+ noCakeMessage.classList.add('hidden');
272
+ resizeCanvas();
273
+ drawCake();
274
+ };
275
+ currentImage.src = imageData;
276
+ }
277
+
278
+ function resizeCanvas() {
279
+ const container = cakeCanvas.parentElement;
280
+ const size = Math.min(container.clientWidth, container.clientHeight);
281
+ cakeCanvas.width = size;
282
+ cakeCanvas.height = size;
283
+
284
+ if (currentImage) {
285
+ drawCake();
286
+ }
287
+ }
288
+
289
+ function drawCake() {
290
+ if (!currentImage) return;
291
+
292
+ const size = cakeCanvas.width;
293
+ ctx.clearRect(0, 0, size, size);
294
+
295
+ // Draw cake image centered and square
296
+ const scale = Math.min(size / currentImage.width, size / currentImage.height);
297
+ const width = currentImage.width * scale;
298
+ const height = currentImage.height * scale;
299
+ const x = (size - width) / 2;
300
+ const y = (size - height) / 2;
301
+
302
+ ctx.drawImage(currentImage, x, y, width, height);
303
+ }
304
+
305
+ function updatePeopleCount(change) {
306
+ people = Math.max(1, Math.min(10, people + change));
307
+ peopleCount.textContent = people;
308
+
309
+ // Update proportions array
310
+ if (change > 0) {
311
+ proportions.push(1); // Add default proportion for new person
312
+ } else {
313
+ proportions.pop(); // Remove last proportion
314
+ }
315
+
316
+ setupProportionControls();
317
+ }
318
+
319
+ function setupProportionControls() {
320
+ proportionControls.innerHTML = '';
321
+
322
+ for (let i = 0; i < people; i++) {
323
+ const controlDiv = document.createElement('div');
324
+ controlDiv.className = 'flex items-center gap-4';
325
+
326
+ const label = document.createElement('span');
327
+ label.className = 'text-amber-700 w-8';
328
+ label.textContent = `P${i+1}:`;
329
+
330
+ const slider = document.createElement('input');
331
+ slider.type = 'range';
332
+ slider.min = '1';
333
+ slider.max = '10';
334
+ slider.value = proportions[i];
335
+ slider.className = 'slice-control flex-1';
336
+ slider.dataset.index = i;
337
+
338
+ const valueDisplay = document.createElement('span');
339
+ valueDisplay.className = 'text-amber-800 font-medium w-8 text-center';
340
+ valueDisplay.textContent = proportions[i];
341
+
342
+ slider.addEventListener('input', function() {
343
+ proportions[this.dataset.index] = parseInt(this.value);
344
+ valueDisplay.textContent = this.value;
345
+ });
346
+
347
+ controlDiv.appendChild(label);
348
+ controlDiv.appendChild(slider);
349
+ controlDiv.appendChild(valueDisplay);
350
+ proportionControls.appendChild(controlDiv);
351
+ }
352
+ }
353
+
354
+ function divideCake() {
355
+ if (!currentImage) {
356
+ alert("Please capture or upload a cake image first.");
357
+ return;
358
+ }
359
+
360
+ const size = cakeCanvas.width;
361
+ ctx.clearRect(0, 0, size, size);
362
+
363
+ // Draw cake image
364
+ const scale = Math.min(size / currentImage.width, size / currentImage.height);
365
+ const width = currentImage.width * scale;
366
+ const height = currentImage.height * scale;
367
+ const x = (size - width) / 2;
368
+ const y = (size - height) / 2;
369
+
370
+ // Calculate total proportions
371
+ const totalProportions = proportions.reduce((a, b) => a + b, 0);
372
+
373
+ // Draw divided cake
374
+ let startAngle = 0;
375
+ const centerX = size / 2;
376
+ const centerY = size / 2;
377
+ const radius = Math.min(width, height) / 2;
378
+
379
+ // Draw each slice
380
+ for (let i = 0; i < people; i++) {
381
+ const sliceAngle = (proportions[i] / totalProportions) * 2 * Math.PI;
382
+ const endAngle = startAngle + sliceAngle;
383
+
384
+ // Create slice path
385
+ ctx.beginPath();
386
+ ctx.moveTo(centerX, centerY);
387
+ ctx.arc(centerX, centerY, radius, startAngle, endAngle);
388
+ ctx.closePath();
389
+
390
+ // Clip and draw cake portion
391
+ ctx.save();
392
+ ctx.clip();
393
+ ctx.drawImage(currentImage, x, y, width, height);
394
+ ctx.restore();
395
+
396
+ // Draw slice border
397
+ ctx.beginPath();
398
+ ctx.moveTo(centerX, centerY);
399
+ ctx.arc(centerX, centerY, radius, startAngle, endAngle);
400
+ ctx.closePath();
401
+ ctx.strokeStyle = 'rgba(255, 255, 255, 0.8)';
402
+ ctx.lineWidth = 4;
403
+ ctx.stroke();
404
+
405
+ // Draw proportion text
406
+ const midAngle = startAngle + sliceAngle / 2;
407
+ const textX = centerX + Math.cos(midAngle) * radius * 0.6;
408
+ const textY = centerY + Math.sin(midAngle) * radius * 0.6;
409
+
410
+ ctx.font = `bold ${Math.max(14, radius * 0.15)}px Arial`;
411
+ ctx.fillStyle = 'white';
412
+ ctx.strokeStyle = 'rgba(0, 0, 0, 0.5)';
413
+ ctx.lineWidth = 3;
414
+ ctx.textAlign = 'center';
415
+ ctx.textBaseline = 'middle';
416
+
417
+ ctx.strokeText(`${proportions[i]}`, textX, textY);
418
+ ctx.fillText(`${proportions[i]}`, textX, textY);
419
+
420
+ startAngle = endAngle;
421
+ }
422
+
423
+ // Show results section
424
+ showResults();
425
+ }
426
+
427
+ function showResults() {
428
+ resultsSection.classList.remove('hidden');
429
+ const resultsContainer = resultsSection.querySelector('.grid');
430
+ resultsContainer.innerHTML = '';
431
+
432
+ // Calculate total proportions
433
+ const totalProportions = proportions.reduce((a, b) => a + b, 0);
434
+
435
+ for (let i = 0; i < people; i++) {
436
+ const percentage = ((proportions[i] / totalProportions) * 100).toFixed(1);
437
+
438
+ const resultCard = document.createElement('div');
439
+ resultCard.className = 'bg-amber-50 rounded-lg p-4 text-center';
440
+
441
+ const colorClass = [
442
+ 'bg-amber-200', 'bg-blue-200', 'bg-green-200', 'bg-red-200',
443
+ 'bg-purple-200', 'bg-pink-200', 'bg-indigo-200', 'bg-yellow-200',
444
+ 'bg-teal-200', 'bg-orange-200'
445
+ ][i % 10];
446
+
447
+ resultCard.innerHTML = `
448
+ <div class="w-16 h-16 ${colorClass} rounded-full flex items-center justify-center mx-auto mb-2">
449
+ <span class="text-xl font-bold">P${i+1}</span>
450
+ </div>
451
+ <h3 class="font-semibold text-amber-800">Person ${i+1}</h3>
452
+ <p class="text-amber-600">${proportions[i]} part(s)</p>
453
+ <p class="text-amber-800 font-bold">${percentage}%</p>
454
+ `;
455
+
456
+ resultsContainer.appendChild(resultCard);
457
+ }
458
+
459
+ // Scroll to results
460
+ resultsSection.scrollIntoView({ behavior: 'smooth' });
461
+ }
462
+ </script>
463
+ <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=Rilaba/splitting-cake" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
464
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ an app for split proportionally a cake by camera