codrizsain commited on
Commit
6184a23
Β·
verified Β·
1 Parent(s): e017306

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +243 -19
index.html CHANGED
@@ -1,19 +1,243 @@
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="id">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Kontrol Lampu AI - Gerakan Tangan</title>
7
+
8
+ <!-- Library MediaPipe Hands (Lebih ringan tanpa FaceMesh) -->
9
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
11
+
12
+ <style>
13
+ body {
14
+ background: radial-gradient(circle at top, #1e293b, #0f172a);
15
+ color: #f8fafc;
16
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
17
+ display: flex; flex-direction: column; align-items: center;
18
+ margin: 0; padding: 20px; min-height: 100vh; overflow-x: hidden;
19
+ }
20
+
21
+ h2 {
22
+ margin-bottom: 5px; color: #38bdf8;
23
+ font-weight: 800; font-size: 24px; text-transform: uppercase; letter-spacing: 1px;
24
+ text-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
25
+ }
26
+ p { color: #94a3b8; margin-top: 0; text-align: center; font-weight: 500; font-size: 14px;}
27
+
28
+ #startBtn {
29
+ background: linear-gradient(135deg, #ec4899, #8b5cf6);
30
+ color: white; border: none; padding: 12px 35px;
31
+ font-size: 16px; border-radius: 50px; cursor: pointer;
32
+ font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
33
+ transition: all 0.3s ease; margin: 15px 0; text-transform: uppercase;
34
+ }
35
+ #startBtn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(236, 72, 153, 0.6); }
36
+
37
+ /* STATUS BOX */
38
+ #statusContainer {
39
+ background: rgba(15, 23, 42, 0.6); border: 1px solid #334155;
40
+ padding: 10px 25px; border-radius: 12px; margin-bottom: 20px;
41
+ text-align: center; backdrop-filter: blur(5px);
42
+ }
43
+ #statusPose { font-size: 18px; font-weight: bold; color: #f8fafc; }
44
+
45
+ /* --- VISUALISASI LAMPU --- */
46
+ #lampStatus {
47
+ font-size: 80px; margin-bottom: 15px;
48
+ transition: all 0.3s ease-in-out;
49
+ text-shadow: 0 0 10px rgba(255,255,255,0.2);
50
+ }
51
+
52
+ /* State Lampu Hidup */
53
+ .lamp-on {
54
+ color: #fbbf24; /* Warna Kuning Amber */
55
+ text-shadow: 0 0 50px #f59e0b, 0 0 80px #f59e0b !important;
56
+ transform: scale(1.1);
57
+ }
58
+
59
+ /* State Lampu Mati */
60
+ .lamp-off {
61
+ color: #475569; /* Warna Abu-abu gelap */
62
+ }
63
+
64
+ /* MONITOR KAMERA */
65
+ .canvas-container {
66
+ position: relative;
67
+ width: 480px; height: 360px; /* Ukuran monitor diperkecil */
68
+ border: 4px solid white;
69
+ box-shadow: 0 10px 30px rgba(0,0,0,0.5);
70
+ border-radius: 16px; overflow: hidden;
71
+ background-color: #000;
72
+ }
73
+
74
+ #videoElement {
75
+ position: absolute; top: 0; left: 0;
76
+ width: 100%; height: 100%; object-fit: cover;
77
+ transform: scaleX(-1); z-index: 1;
78
+ }
79
+
80
+ #outputCanvas {
81
+ position: absolute; top: 0; left: 0;
82
+ width: 100%; height: 100%; object-fit: cover;
83
+ transform: scaleX(-1); z-index: 2;
84
+ background-color: transparent;
85
+ }
86
+
87
+ </style>
88
+ </head>
89
+ <body>
90
+
91
+ <h2>⚑ AI Lamp Control</h2>
92
+ <p>πŸ–οΈ Hidupkan | ✌️ Matikan</p>
93
+
94
+ <button id="startBtn">β–Ά Aktifkan Kamera</button>
95
+
96
+ <!-- TAMPILAN STATUS POSE -->
97
+ <div id="statusContainer">
98
+ <div id="statusPose">Menunggu Kamera...</div>
99
+ </div>
100
+
101
+ <!-- VISUALISASI LAMPU (Menggunakan Emoji) -->
102
+ <div id="lampStatus" class="lamp-off">πŸ’‘</div>
103
+
104
+ <div class="canvas-container">
105
+ <!-- Kamera langsung muncul via WebRTC -->
106
+ <video id="videoElement" autoplay playsinline webkit-playsinline muted></video>
107
+ <canvas id="outputCanvas" width="480" height="360"></canvas>
108
+ </div>
109
+
110
+ <script>
111
+ const videoElement = document.getElementById('videoElement');
112
+ const canvasElement = document.getElementById('outputCanvas');
113
+ const canvasCtx = canvasElement.getContext('2d');
114
+ const startBtn = document.getElementById('startBtn');
115
+ const statusPose = document.getElementById('statusPose');
116
+ const lampStatus = document.getElementById('lampStatus');
117
+
118
+ // Status Lampu: false = mati, true = hidup
119
+ let isLampOn = false;
120
+
121
+ // --- LOGIKA DETEKSI GERAKAN ---
122
+ function analyzePoses(multiHandLandmarks) {
123
+ if (!multiHandLandmarks || multiHandLandmarks.length === 0) return null;
124
+
125
+ // Kita hanya ambil tangan pertama yang terdeteksi
126
+ const lm = multiHandLandmarks[0];
127
+
128
+ // Cek kondisi jari berdiri (y tip < y base joint)
129
+ const indexUp = lm[8].y < lm[6].y;
130
+ const middleUp = lm[12].y < lm[10].y;
131
+ const ringUp = lm[16].y < lm[14].y;
132
+ const pinkyUp = lm[20].y < lm[18].y;
133
+
134
+ // Hitung jumlah jari yang berdiri (selain jempol)
135
+ const fingersUpCount = [indexUp, middleUp, ringUp, pinkyUp].filter(Boolean).length;
136
+
137
+ // LOGIKA POSE πŸ–οΈ (Telapak Terbuka): Minimal 3 jari berdiri lebar
138
+ if (fingersUpCount >= 3) {
139
+ return 'palm';
140
+ }
141
+
142
+ // LOGIKA POSE ✌️ (Victory): Hanya Telunjuk dan Tengah yang berdiri
143
+ if (indexUp && middleUp && !ringUp && !pinkyUp) {
144
+ return 'victory';
145
+ }
146
+
147
+ return null; // Tidak ada pose yang cocok
148
+ }
149
+
150
+ // --- SETUP MEDIAPIPE HANDS (Ringan) ---
151
+ const hands = new Hands({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`});
152
+
153
+ hands.setOptions({
154
+ maxNumHands: 1, // Hanya deteksi 1 tangan agar cepat
155
+ modelComplexity: 0, // Sangat ringan & responsif
156
+ minDetectionConfidence: 0.7,
157
+ minTrackingConfidence: 0.7
158
+ });
159
+
160
+ hands.onResults((results) => {
161
+ canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
162
+
163
+ // Gambar tulang tangan (Biru muda)
164
+ if (results.multiHandLandmarks) {
165
+ results.multiHandLandmarks.forEach((landmarks) => {
166
+ drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: '#38bdf8', lineWidth: 3});
167
+ drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 1, radius: 2});
168
+ });
169
+ }
170
+
171
+ // Analisis Pose
172
+ const detectedPose = analyzePoses(results.multiHandLandmarks);
173
+
174
+ // --- EKSEKUSI KONTROL LAMPU (TANPA SUARA) ---
175
+ if (detectedPose === 'palm') {
176
+ if (!isLampOn) {
177
+ isLampOn = true;
178
+ // Update Tampilan Lampu Hidup
179
+ lampStatus.className = 'lamp-on';
180
+ lampStatus.textContent = 'πŸ’‘';
181
+
182
+ statusPose.textContent = "πŸ–οΈ Pose: Menghidupkan";
183
+ statusPose.style.color = "#fbbf24"; // Kuning
184
+ }
185
+ }
186
+ else if (detectedPose === 'victory') {
187
+ if (isLampOn) {
188
+ isLampOn = false;
189
+ // Update Tampilan Lampu Mati
190
+ lampStatus.className = 'lamp-off';
191
+ lampStatus.textContent = 'πŸ’‘';
192
+
193
+ statusPose.textContent = "✌️ Pose: Mematikan";
194
+ statusPose.style.color = "#ec4899"; // Pink
195
+ }
196
+ }
197
+ else if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
198
+ // Tangan terdeteksi tapi pose tidak cocok
199
+ statusPose.textContent = "πŸ–οΈ/✌️ Gunakan Gerakan";
200
+ statusPose.style.color = "#f8fafc";
201
+ }
202
+ else {
203
+ // Tidak ada tangan
204
+ statusPose.textContent = "Arahkan Tangan";
205
+ statusPose.style.color = "#94a3b8";
206
+ }
207
+ });
208
+
209
+ // --- CUSTOM CAMERA ENGINE (WebRTC Manual) ---
210
+ startBtn.addEventListener('click', async () => {
211
+ startBtn.style.display = 'none';
212
+ statusPose.textContent = "Meminta Izin Kamera...";
213
+
214
+ try {
215
+ // Memanggil Kamera Manual (Mencegah blank di Chrome)
216
+ const stream = await navigator.mediaDevices.getUserMedia({
217
+ video: { width: 480, height: 360 }
218
+ });
219
+ videoElement.srcObject = stream;
220
+
221
+ videoElement.onloadedmetadata = () => {
222
+ videoElement.play();
223
+ statusPose.textContent = "AI Siap! πŸš€";
224
+ statusPose.style.color = "#f8fafc";
225
+
226
+ // Loop AI Frame dinamis
227
+ async function processFrame() {
228
+ if (!videoElement.paused && !videoElement.ended) {
229
+ await hands.send({image: videoElement});
230
+ }
231
+ requestAnimationFrame(processFrame);
232
+ }
233
+ processFrame();
234
+ };
235
+ } catch (error) {
236
+ alert("GAGAL AKSES KAMERA!\nBrowser memblokir kamera. Tolong klik icon gembok di sebelah URL / berikan izin 'Allow Camera'.\n\nDetail: " + error.message);
237
+ statusPose.textContent = "Kamera Terblokir πŸ”΄";
238
+ startBtn.style.display = 'block';
239
+ }
240
+ });
241
+ </script>
242
+ </body>
243
+ </html>