Riceunjae commited on
Commit
6a4d3bb
·
1 Parent(s): 3ee442d

Deploy Project_TPA_AI to HuggingFace Spaces

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ models/*.h5 filter=lfs diff=lfs merge=lfs -text
37
+ models/*.pkl filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,10 +1,58 @@
1
- ---
2
- title: Project TPA AI
3
- emoji: 🦀
4
- colorFrom: indigo
5
- colorTo: green
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Daurin AI Hub
2
+
3
+ Backend AI untuk klasifikasi sampah, clustering TPA, dan prediksi emisi metana.
4
+
5
+ ## Fitur
6
+
7
+ - `FastAPI` untuk API inference model.
8
+ - Endpoint prediksi untuk CNN, K-Means, dan regresi.
9
+ - Dokumen otomatis di `/docs`.
10
+ - Health check di `/health`.
11
+ - Siap dijalankan dengan Docker.
12
+
13
+ ## Menjalankan Lokal
14
+
15
+ ```bash
16
+ pip install -r requirements.txt
17
+ uvicorn main:app --reload
18
+ ```
19
+
20
+ Buka:
21
+
22
+ - API: `http://127.0.0.1:8000`
23
+ - Swagger: `http://127.0.0.1:8000/docs`
24
+
25
+ ## Endpoint
26
+
27
+ - `GET /` - status layanan.
28
+ - `GET /health` - status readiness model.
29
+ - `POST /predict-cnn` - prediksi gambar sampah.
30
+ - `POST /predict-kmeans` - clustering data TPA.
31
+ - `POST /predict-regression` - prediksi metana.
32
+
33
+ ## Deploy ke HuggingFace Spaces
34
+
35
+ 1. Buat Space baru.
36
+ 2. Pilih `Docker` sebagai SDK.
37
+ 3. Upload seluruh isi repository ini.
38
+ 4. HuggingFace akan membaca `Dockerfile` dan menjalankan aplikasi pada port `7860`.
39
+
40
+ ## Deploy ke Render
41
+
42
+ 1. Buat Web Service baru dari repository ini.
43
+ 2. Pilih environment `Docker`.
44
+ 3. Render akan memakai `Dockerfile` dan membaca port dari env `PORT`.
45
+ 4. Gunakan health check path `/health`.
46
+
47
+ ## Deploy ke VPS
48
+
49
+ ```bash
50
+ docker build -t daurin-ai-hub .
51
+ docker run -p 8000:8000 -e PORT=8000 daurin-ai-hub
52
+ ```
53
+
54
+ Kalau tidak memakai Docker, jalankan:
55
+
56
+ ```bash
57
+ uvicorn main:app --host 0.0.0.0 --port 8000
58
+ ```
app.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+
3
+ app = FastAPI()
4
+
5
+
6
+ @app.get("/")
7
+ def greet_json():
8
+ return {"Hello": "World!"}
daurin-ai-hub.html ADDED
@@ -0,0 +1,1002 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Daurin AI Hub</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
8
+ <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet" />
9
+ <style>
10
+ :root {
11
+ --green-50: #f0fdf4;
12
+ --green-100: #dcfce7;
13
+ --green-200: #bbf7d0;
14
+ --green-400: #4ade80;
15
+ --green-500: #22c55e;
16
+ --green-600: #16a34a;
17
+ --green-700: #15803d;
18
+ --green-900: #14532d;
19
+ --gray-50: #f9fafb;
20
+ --gray-100: #f3f4f6;
21
+ --gray-200: #e5e7eb;
22
+ --gray-300: #d1d5db;
23
+ --gray-400: #9ca3af;
24
+ --gray-500: #6b7280;
25
+ --gray-700: #374151;
26
+ --gray-800: #1f2937;
27
+ --gray-900: #111827;
28
+ --white: #ffffff;
29
+ --radius-sm: 8px;
30
+ --radius-md: 12px;
31
+ --radius-lg: 16px;
32
+ --radius-xl: 24px;
33
+ --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
34
+ --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
35
+ --shadow-lg: 0 12px 40px rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.05);
36
+ --font-main: 'Plus Jakarta Sans', sans-serif;
37
+ --font-mono: 'Space Mono', monospace;
38
+ }
39
+
40
+ * { box-sizing: border-box; margin: 0; padding: 0; }
41
+
42
+ body {
43
+ font-family: var(--font-main);
44
+ background: var(--gray-50);
45
+ color: var(--gray-900);
46
+ min-height: 100vh;
47
+ }
48
+
49
+ /* ── NOISE TEXTURE OVERLAY ── */
50
+ body::before {
51
+ content: '';
52
+ position: fixed;
53
+ inset: 0;
54
+ background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
55
+ pointer-events: none;
56
+ z-index: 0;
57
+ }
58
+
59
+ /* ── HEADER ── */
60
+ .header {
61
+ background: var(--white);
62
+ border-bottom: 1px solid var(--gray-200);
63
+ padding: 0 2rem;
64
+ position: sticky;
65
+ top: 0;
66
+ z-index: 100;
67
+ box-shadow: var(--shadow-sm);
68
+ }
69
+
70
+ .header-inner {
71
+ max-width: 1200px;
72
+ margin: 0 auto;
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: space-between;
76
+ height: 64px;
77
+ }
78
+
79
+ .logo {
80
+ display: flex;
81
+ align-items: center;
82
+ gap: 12px;
83
+ }
84
+
85
+ .logo-icon {
86
+ width: 40px;
87
+ height: 40px;
88
+ background: linear-gradient(135deg, var(--green-600), var(--green-400));
89
+ border-radius: var(--radius-sm);
90
+ display: flex;
91
+ align-items: center;
92
+ justify-content: center;
93
+ box-shadow: 0 2px 8px rgba(22,163,74,0.3);
94
+ }
95
+
96
+ .logo-icon svg { width: 22px; height: 22px; }
97
+
98
+ .logo-text {
99
+ font-size: 18px;
100
+ font-weight: 800;
101
+ color: var(--gray-900);
102
+ letter-spacing: -0.3px;
103
+ }
104
+
105
+ .logo-text span { color: var(--green-600); }
106
+
107
+ .header-badge {
108
+ display: flex;
109
+ align-items: center;
110
+ gap: 8px;
111
+ font-size: 12px;
112
+ color: var(--gray-500);
113
+ font-family: var(--font-mono);
114
+ }
115
+
116
+ .badge-pill {
117
+ background: var(--green-100);
118
+ color: var(--green-700);
119
+ padding: 3px 10px;
120
+ border-radius: 20px;
121
+ font-weight: 600;
122
+ font-size: 11px;
123
+ font-family: var(--font-mono);
124
+ }
125
+
126
+ .status-dot {
127
+ width: 7px;
128
+ height: 7px;
129
+ background: var(--green-500);
130
+ border-radius: 50%;
131
+ animation: pulse 2s infinite;
132
+ }
133
+
134
+ @keyframes pulse {
135
+ 0%, 100% { opacity: 1; }
136
+ 50% { opacity: 0.4; }
137
+ }
138
+
139
+ /* ── HERO ── */
140
+ .hero {
141
+ max-width: 1200px;
142
+ margin: 0 auto;
143
+ padding: 3rem 2rem 2rem;
144
+ position: relative;
145
+ z-index: 1;
146
+ }
147
+
148
+ .hero-label {
149
+ display: inline-flex;
150
+ align-items: center;
151
+ gap: 6px;
152
+ background: var(--green-100);
153
+ color: var(--green-700);
154
+ font-size: 12px;
155
+ font-weight: 600;
156
+ padding: 5px 12px;
157
+ border-radius: 20px;
158
+ margin-bottom: 1rem;
159
+ font-family: var(--font-mono);
160
+ letter-spacing: 0.5px;
161
+ }
162
+
163
+ .hero h1 {
164
+ font-size: clamp(28px, 4vw, 42px);
165
+ font-weight: 800;
166
+ line-height: 1.15;
167
+ color: var(--gray-900);
168
+ letter-spacing: -1px;
169
+ margin-bottom: 0.75rem;
170
+ }
171
+
172
+ .hero h1 em {
173
+ font-style: normal;
174
+ color: var(--green-600);
175
+ }
176
+
177
+ .hero p {
178
+ font-size: 15px;
179
+ color: var(--gray-500);
180
+ max-width: 520px;
181
+ line-height: 1.6;
182
+ }
183
+
184
+ /* ── GRID ── */
185
+ .main-grid {
186
+ max-width: 1200px;
187
+ margin: 0 auto;
188
+ padding: 0 2rem 3rem;
189
+ display: grid;
190
+ grid-template-columns: repeat(3, 1fr);
191
+ gap: 20px;
192
+ position: relative;
193
+ z-index: 1;
194
+ }
195
+
196
+ @media (max-width: 900px) {
197
+ .main-grid { grid-template-columns: 1fr; }
198
+ }
199
+
200
+ /* ── CARD ── */
201
+ .card {
202
+ background: var(--white);
203
+ border: 1px solid var(--gray-200);
204
+ border-radius: var(--radius-xl);
205
+ padding: 1.5rem;
206
+ display: flex;
207
+ flex-direction: column;
208
+ gap: 16px;
209
+ box-shadow: var(--shadow-sm);
210
+ transition: box-shadow 0.2s, transform 0.2s;
211
+ }
212
+
213
+ .card:hover {
214
+ box-shadow: var(--shadow-md);
215
+ transform: translateY(-2px);
216
+ }
217
+
218
+ .card-header { display: flex; flex-direction: column; gap: 4px; }
219
+
220
+ .card-tag {
221
+ font-size: 10px;
222
+ font-weight: 700;
223
+ color: var(--gray-400);
224
+ letter-spacing: 1.5px;
225
+ text-transform: uppercase;
226
+ font-family: var(--font-mono);
227
+ }
228
+
229
+ .card-title {
230
+ font-size: 17px;
231
+ font-weight: 700;
232
+ color: var(--gray-900);
233
+ line-height: 1.3;
234
+ letter-spacing: -0.3px;
235
+ }
236
+
237
+ .card-title span { color: var(--green-600); }
238
+
239
+ /* ── DROP ZONE ── */
240
+ .drop-zone {
241
+ border: 1.5px dashed var(--green-400);
242
+ border-radius: var(--radius-lg);
243
+ padding: 1.5rem 1rem;
244
+ text-align: center;
245
+ cursor: pointer;
246
+ background: var(--green-50);
247
+ transition: all 0.2s;
248
+ min-height: 150px;
249
+ display: flex;
250
+ flex-direction: column;
251
+ align-items: center;
252
+ justify-content: center;
253
+ gap: 10px;
254
+ position: relative;
255
+ overflow: hidden;
256
+ }
257
+
258
+ .drop-zone:hover, .drop-zone.dragover {
259
+ background: var(--green-100);
260
+ border-color: var(--green-600);
261
+ }
262
+
263
+ .drop-zone-icon {
264
+ width: 44px;
265
+ height: 44px;
266
+ background: var(--green-100);
267
+ border-radius: var(--radius-sm);
268
+ display: flex;
269
+ align-items: center;
270
+ justify-content: center;
271
+ }
272
+
273
+ .drop-zone-icon svg { width: 22px; height: 22px; color: var(--green-600); }
274
+
275
+ .drop-zone-label { font-size: 13px; font-weight: 600; color: var(--green-700); }
276
+ .drop-zone-sub { font-size: 11px; color: var(--green-500); }
277
+
278
+ .preview-img {
279
+ max-height: 90px;
280
+ border-radius: var(--radius-sm);
281
+ object-fit: cover;
282
+ display: none;
283
+ box-shadow: var(--shadow-sm);
284
+ }
285
+
286
+ /* ── RESULT BOX ── */
287
+ .result-box {
288
+ background: var(--gray-50);
289
+ border: 1px solid var(--gray-200);
290
+ border-radius: var(--radius-md);
291
+ padding: 12px 14px;
292
+ }
293
+
294
+ .result-label {
295
+ font-size: 10px;
296
+ font-weight: 700;
297
+ color: var(--gray-400);
298
+ text-transform: uppercase;
299
+ letter-spacing: 1px;
300
+ font-family: var(--font-mono);
301
+ margin-bottom: 6px;
302
+ }
303
+
304
+ .result-value {
305
+ font-size: 13px;
306
+ font-weight: 500;
307
+ color: var(--gray-700);
308
+ line-height: 1.5;
309
+ }
310
+
311
+ .result-value.loading { color: var(--gray-400); font-style: italic; }
312
+
313
+ .result-chip {
314
+ display: inline-flex;
315
+ align-items: center;
316
+ gap: 5px;
317
+ padding: 4px 10px;
318
+ border-radius: 20px;
319
+ font-size: 12px;
320
+ font-weight: 600;
321
+ }
322
+
323
+ .chip-green { background: var(--green-100); color: var(--green-700); }
324
+ .chip-yellow { background: #fef3c7; color: #92400e; }
325
+ .chip-red { background: #fee2e2; color: #991b1b; }
326
+ .chip-blue { background: #eff6ff; color: #1e40af; }
327
+
328
+ /* ── HEX GRID ── */
329
+ .hex-container {
330
+ background: var(--green-50);
331
+ border: 1px solid var(--green-200);
332
+ border-radius: var(--radius-lg);
333
+ padding: 14px;
334
+ display: flex;
335
+ flex-direction: column;
336
+ align-items: center;
337
+ gap: 4px;
338
+ min-height: 130px;
339
+ justify-content: center;
340
+ position: relative;
341
+ }
342
+
343
+ .hex-row { display: flex; gap: 3px; }
344
+
345
+ .hex-cell {
346
+ width: 28px;
347
+ height: 24px;
348
+ cursor: pointer;
349
+ position: relative;
350
+ transition: transform 0.15s;
351
+ }
352
+
353
+ .hex-cell:hover { transform: scale(1.15); z-index: 2; }
354
+
355
+ .hex-cell svg { width: 100%; height: 100%; }
356
+
357
+ .hex-tooltip {
358
+ position: fixed;
359
+ background: var(--gray-900);
360
+ color: var(--white);
361
+ font-size: 11px;
362
+ padding: 6px 10px;
363
+ border-radius: var(--radius-sm);
364
+ pointer-events: none;
365
+ display: none;
366
+ z-index: 999;
367
+ white-space: nowrap;
368
+ font-family: var(--font-mono);
369
+ line-height: 1.5;
370
+ }
371
+
372
+ /* ── FEATURE INPUTS ── */
373
+ .input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
374
+ .input-grid.single { grid-template-columns: 1fr; }
375
+
376
+ .inp-wrap { display: flex; flex-direction: column; gap: 4px; }
377
+
378
+ .inp-label {
379
+ font-size: 10px;
380
+ font-weight: 700;
381
+ color: var(--gray-400);
382
+ text-transform: uppercase;
383
+ letter-spacing: 0.8px;
384
+ font-family: var(--font-mono);
385
+ }
386
+
387
+ .inp {
388
+ width: 100%;
389
+ padding: 8px 10px;
390
+ border: 1px solid var(--gray-200);
391
+ border-radius: var(--radius-sm);
392
+ background: var(--white);
393
+ font-size: 13px;
394
+ font-family: var(--font-mono);
395
+ color: var(--gray-800);
396
+ transition: border-color 0.15s;
397
+ outline: none;
398
+ }
399
+
400
+ .inp:focus { border-color: var(--green-400); }
401
+
402
+ .features-input {
403
+ background: var(--gray-50);
404
+ border: 1px solid var(--gray-200);
405
+ border-radius: var(--radius-md);
406
+ padding: 12px;
407
+ display: flex;
408
+ flex-direction: column;
409
+ gap: 8px;
410
+ }
411
+
412
+ .features-title {
413
+ font-size: 10px;
414
+ font-weight: 700;
415
+ color: var(--gray-400);
416
+ text-transform: uppercase;
417
+ letter-spacing: 1px;
418
+ font-family: var(--font-mono);
419
+ }
420
+
421
+ .feat-row {
422
+ display: flex;
423
+ align-items: center;
424
+ gap: 8px;
425
+ }
426
+
427
+ .feat-badge {
428
+ background: var(--green-100);
429
+ color: var(--green-700);
430
+ font-size: 10px;
431
+ font-weight: 700;
432
+ font-family: var(--font-mono);
433
+ width: 28px;
434
+ height: 28px;
435
+ border-radius: 6px;
436
+ display: flex;
437
+ align-items: center;
438
+ justify-content: center;
439
+ flex-shrink: 0;
440
+ }
441
+
442
+ .feat-desc { font-size: 11px; color: var(--gray-500); flex: 1; line-height: 1.3; }
443
+
444
+ /* ── CHART ── */
445
+ .chart-wrap {
446
+ background: var(--green-50);
447
+ border: 1px solid var(--green-200);
448
+ border-radius: var(--radius-lg);
449
+ padding: 12px;
450
+ height: 130px;
451
+ position: relative;
452
+ }
453
+
454
+ /* ── ZONE LEGEND ── */
455
+ .zone-legend {
456
+ display: flex;
457
+ gap: 12px;
458
+ font-size: 11px;
459
+ color: var(--gray-600);
460
+ font-weight: 500;
461
+ }
462
+
463
+ .zone-dot {
464
+ width: 8px;
465
+ height: 8px;
466
+ border-radius: 50%;
467
+ display: inline-block;
468
+ margin-right: 4px;
469
+ }
470
+
471
+ /* ── BUTTON ── */
472
+ .btn-primary {
473
+ background: var(--green-600);
474
+ color: var(--white);
475
+ border: none;
476
+ border-radius: var(--radius-md);
477
+ padding: 12px 16px;
478
+ font-size: 14px;
479
+ font-weight: 700;
480
+ font-family: var(--font-main);
481
+ cursor: pointer;
482
+ width: 100%;
483
+ transition: all 0.2s;
484
+ display: flex;
485
+ align-items: center;
486
+ justify-content: center;
487
+ gap: 8px;
488
+ letter-spacing: 0.3px;
489
+ margin-top: auto;
490
+ }
491
+
492
+ .btn-primary:hover:not(:disabled) {
493
+ background: var(--green-700);
494
+ transform: translateY(-1px);
495
+ box-shadow: 0 4px 12px rgba(22,163,74,0.35);
496
+ }
497
+
498
+ .btn-primary:active:not(:disabled) { transform: translateY(0); }
499
+ .btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; transform: none; box-shadow: none; }
500
+
501
+ .spinner {
502
+ width: 14px;
503
+ height: 14px;
504
+ border: 2px solid rgba(255,255,255,0.4);
505
+ border-top-color: var(--white);
506
+ border-radius: 50%;
507
+ animation: spin 0.7s linear infinite;
508
+ flex-shrink: 0;
509
+ }
510
+
511
+ @keyframes spin { to { transform: rotate(360deg); } }
512
+
513
+ /* ── FOOTER ── */
514
+ .footer {
515
+ text-align: center;
516
+ padding: 1.5rem;
517
+ font-size: 12px;
518
+ color: var(--gray-400);
519
+ position: relative;
520
+ z-index: 1;
521
+ font-family: var(--font-mono);
522
+ }
523
+
524
+ input[type="file"] { display: none; }
525
+ </style>
526
+ </head>
527
+ <body>
528
+
529
+ <!-- HEADER -->
530
+ <header class="header">
531
+ <div class="header-inner">
532
+ <div class="logo">
533
+ <div class="logo-icon">
534
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
535
+ <path d="M12 2L8 7H16L12 2Z" fill="white" opacity="0.9"/>
536
+ <path d="M5 17L2 22H10L5 17Z" fill="white" opacity="0.7"/>
537
+ <path d="M19 17L16 22H22L19 17Z" fill="white" opacity="0.8"/>
538
+ <path d="M12 7L5 17H19L12 7Z" fill="white" opacity="0.5"/>
539
+ </svg>
540
+ </div>
541
+ <span class="logo-text">Daurin <span>AI</span> Hub</span>
542
+ </div>
543
+ <div class="header-badge">
544
+ <div class="status-dot"></div>
545
+ <span>API Online</span>
546
+ <span class="badge-pill">v1.0.0</span>
547
+ </div>
548
+ </div>
549
+ </header>
550
+
551
+ <!-- HERO -->
552
+ <section class="hero">
553
+ <div class="hero-label">
554
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>
555
+ Platform Manajemen Sampah Cerdas
556
+ </div>
557
+ <h1>3 Model AI untuk <em>Efisiensi</em><br/>Pengelolaan Sampah</h1>
558
+ <p>Klasifikasi jenis sampah, zonasi TPA, dan prediksi emisi metana — semua dalam satu platform terintegrasi.</p>
559
+ </section>
560
+
561
+ <!-- MAIN GRID -->
562
+ <main class="main-grid">
563
+
564
+ <!-- ═══ CARD 1: CNN ═══ -->
565
+ <div class="card">
566
+ <div class="card-header">
567
+ <div class="card-tag">Boks Fitur 1 · POST /predict-cnn</div>
568
+ <div class="card-title">Waste Classification <span>— CNN</span></div>
569
+ </div>
570
+
571
+ <div class="drop-zone" id="dropZone"
572
+ onclick="document.getElementById('fileInput').click()"
573
+ ondragover="ev(event,'dragover',true)"
574
+ ondragleave="ev(event,'dragover',false)"
575
+ ondrop="handleDrop(event)">
576
+ <div class="drop-zone-icon" id="dzIcon">
577
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
578
+ </div>
579
+ <img id="previewImg" class="preview-img" alt="Preview" />
580
+ <div class="drop-zone-label" id="dzLabel">Drag & Drop Gambar</div>
581
+ <div class="drop-zone-sub" id="dzSub">JPG atau PNG · Maks. 10MB</div>
582
+ </div>
583
+ <input type="file" id="fileInput" accept="image/jpeg,image/png" onchange="handleFile(this.files[0])">
584
+
585
+ <div class="result-box">
586
+ <div class="result-label">Hasil Klasifikasi</div>
587
+ <div class="result-value loading" id="cnnVal">— Upload gambar untuk mulai</div>
588
+ </div>
589
+
590
+ <button class="btn-primary" id="btnCnn" onclick="predictCNN()">
591
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><rect x="5" y="2" width="14" height="20" rx="2"/><line x1="9" y1="9" x2="15" y2="9"/><line x1="9" y1="13" x2="15" y2="13"/></svg>
592
+ Daurin — Klasifikasi
593
+ </button>
594
+ </div>
595
+
596
+ <!-- ═══ CARD 2: K-MEANS ═══ -->
597
+ <div class="card">
598
+ <div class="card-header">
599
+ <div class="card-tag">Boks Fitur 2 · POST /predict-kmeans</div>
600
+ <div class="card-title">TPA Clustering <span>— K-Means</span></div>
601
+ </div>
602
+
603
+ <div class="hex-container" id="hexContainer" aria-label="Peta zona TPA"></div>
604
+
605
+ <div class="zone-legend">
606
+ <span><span class="zone-dot" style="background:#22c55e"></span>Aman</span>
607
+ <span><span class="zone-dot" style="background:#eab308"></span>Sedang</span>
608
+ <span><span class="zone-dot" style="background:#ef4444"></span>Kritis</span>
609
+ </div>
610
+
611
+ <div class="features-input">
612
+ <div class="features-title">Input Fitur (list[float])</div>
613
+ <div class="feat-row">
614
+ <div class="feat-badge">F1</div>
615
+ <div class="feat-desc">Volume sampah / kapasitas TPA</div>
616
+ <input class="inp" id="km1" type="number" value="0.45" step="0.01" style="width:80px;flex-shrink:0" />
617
+ </div>
618
+ <div class="feat-row">
619
+ <div class="feat-badge">F2</div>
620
+ <div class="feat-desc">Kepadatan populasi sekitar</div>
621
+ <input class="inp" id="km2" type="number" value="1.20" step="0.01" style="width:80px;flex-shrink:0" />
622
+ </div>
623
+ <div class="feat-row">
624
+ <div class="feat-badge">F3</div>
625
+ <div class="feat-desc">Jarak ke pemukiman (km)</div>
626
+ <input class="inp" id="km3" type="number" value="3.44" step="0.01" style="width:80px;flex-shrink:0" />
627
+ </div>
628
+ <div class="feat-row">
629
+ <div class="feat-badge">F4</div>
630
+ <div class="feat-desc">Indeks risiko lingkungan</div>
631
+ <input class="inp" id="km4" type="number" value="0.12" step="0.01" style="width:80px;flex-shrink:0" />
632
+ </div>
633
+ </div>
634
+
635
+ <div class="result-box">
636
+ <div class="result-label">Zona Klaster TPA</div>
637
+ <div class="result-value loading" id="kmeansVal">— Isi fitur &amp; klik Daurin</div>
638
+ </div>
639
+
640
+ <button class="btn-primary" id="btnKmeans" onclick="predictKMeans()">
641
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="3"/><path d="M5.6 5.6l1.4 1.4M16.6 16.6l1.4 1.4M5.6 18.4l1.4-1.4M16.6 7.4l1.4-1.4"/><circle cx="12" cy="12" r="8" stroke-dasharray="3 3"/></svg>
642
+ Daurin — Clustering
643
+ </button>
644
+ </div>
645
+
646
+ <!-- ═══ CARD 3: REGRESSION ═══ -->
647
+ <div class="card">
648
+ <div class="card-header">
649
+ <div class="card-tag">Boks Fitur 3 · POST /predict-regression</div>
650
+ <div class="card-title">Methane Prediction <span>— Regression</span></div>
651
+ </div>
652
+
653
+ <div class="chart-wrap">
654
+ <canvas id="methaneChart"></canvas>
655
+ </div>
656
+
657
+ <div class="features-input">
658
+ <div class="features-title">Input Fitur (list[float])</div>
659
+ <div class="feat-row">
660
+ <div class="feat-badge">F1</div>
661
+ <div class="feat-desc">Suhu rata-rata (°C)</div>
662
+ <input class="inp" id="rg1" type="number" value="25.5" step="0.1" style="width:80px;flex-shrink:0" />
663
+ </div>
664
+ <div class="feat-row">
665
+ <div class="feat-badge">F2</div>
666
+ <div class="feat-desc">Volume sampah organik (ton)</div>
667
+ <input class="inp" id="rg2" type="number" value="400.0" step="1" style="width:80px;flex-shrink:0" />
668
+ </div>
669
+ <div class="feat-row">
670
+ <div class="feat-badge">F3</div>
671
+ <div class="feat-desc">Kelembaban udara (%)</div>
672
+ <input class="inp" id="rg3" type="number" value="12.3" step="0.1" style="width:80px;flex-shrink:0" />
673
+ </div>
674
+ </div>
675
+
676
+ <div class="result-box">
677
+ <div class="result-label">Prediksi Emisi Metana</div>
678
+ <div class="result-value loading" id="regVal">— Isi fitur &amp; klik Daurin</div>
679
+ </div>
680
+
681
+ <button class="btn-primary" id="btnReg" onclick="predictRegression()">
682
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>
683
+ Daurin — Prediksi Metana
684
+ </button>
685
+ </div>
686
+
687
+ </main>
688
+
689
+ <!-- TOOLTIP -->
690
+ <div class="hex-tooltip" id="hexTip"></div>
691
+
692
+ <!-- FOOTER -->
693
+ <footer class="footer">
694
+ Daurin AI Hub · Platform Backend Cerdas Berbasis 3 Model AI · <a href="https://kifliii-api-manajemen-tpa.hf.space/docs" style="color:var(--green-600);text-decoration:none;" target="_blank">Swagger Docs ↗</a>
695
+ </footer>
696
+
697
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.umd.min.js"></script>
698
+ <script>
699
+ const API = "https://kifliii-api-manajemen-tpa.hf.space";
700
+ let selectedFile = null;
701
+ let chart = null;
702
+ let chartHistory = [];
703
+
704
+ // ── CLASS MAP ──
705
+ const CLASS_NAMES = {
706
+ 0: "Plastik",
707
+ 1: "Kertas",
708
+ 2: "Kaca",
709
+ 3: "Logam",
710
+ 4: "Organik",
711
+ 5: "Sampah B3",
712
+ 6: "Kardus",
713
+ 7: "Tekstil"
714
+ };
715
+
716
+ const CLUSTER_MAP = {
717
+ 0: { label: "Zona Aman", chipClass: "chip-green", hexColor: "#22c55e" },
718
+ 1: { label: "Zona Sedang", chipClass: "chip-yellow", hexColor: "#eab308" },
719
+ 2: { label: "Zona Kritis", chipClass: "chip-red", hexColor: "#ef4444" }
720
+ };
721
+
722
+ // ── HELPERS ──
723
+ function ev(e, cls, add) {
724
+ e.preventDefault();
725
+ document.getElementById('dropZone').classList.toggle(cls, add);
726
+ }
727
+
728
+ function setLoading(btnId, loading, defaultHTML) {
729
+ const btn = document.getElementById(btnId);
730
+ btn.disabled = loading;
731
+ btn.innerHTML = loading
732
+ ? '<div class="spinner"></div> Memproses...'
733
+ : defaultHTML;
734
+ }
735
+
736
+ function setResult(elId, html, isLoading = false) {
737
+ const el = document.getElementById(elId);
738
+ el.innerHTML = html;
739
+ el.className = 'result-value' + (isLoading ? ' loading' : '');
740
+ }
741
+
742
+ // ── FILE HANDLING ──
743
+ function handleFile(file) {
744
+ if (!file) return;
745
+ selectedFile = file;
746
+ const reader = new FileReader();
747
+ reader.onload = e => {
748
+ const img = document.getElementById('previewImg');
749
+ img.src = e.target.result;
750
+ img.style.display = 'block';
751
+ document.getElementById('dzIcon').style.display = 'none';
752
+ document.getElementById('dzLabel').textContent = file.name;
753
+ document.getElementById('dzSub').textContent = (file.size / 1024).toFixed(1) + ' KB · siap diklasifikasi';
754
+ };
755
+ reader.readAsDataURL(file);
756
+ }
757
+
758
+ function handleDrop(e) {
759
+ e.preventDefault();
760
+ document.getElementById('dropZone').classList.remove('dragover');
761
+ const file = e.dataTransfer.files[0];
762
+ if (file && (file.type === 'image/jpeg' || file.type === 'image/png')) {
763
+ handleFile(file);
764
+ } else {
765
+ alert('Format file harus JPG atau PNG.');
766
+ }
767
+ }
768
+
769
+ // ── CNN ──
770
+ async function predictCNN() {
771
+ if (!selectedFile) {
772
+ setResult('cnnVal', '⚠ Upload gambar terlebih dahulu');
773
+ return;
774
+ }
775
+ setLoading('btnCnn', true);
776
+ setResult('cnnVal', 'Menganalisis gambar...', true);
777
+
778
+ try {
779
+ const form = new FormData();
780
+ form.append('file', selectedFile);
781
+ const res = await fetch(API + '/predict-cnn', { method: 'POST', body: form });
782
+ if (!res.ok) throw new Error('HTTP ' + res.status);
783
+ const data = await res.json();
784
+ const idx = data.result?.predicted_class_index ?? 0;
785
+ const conf = data.result?.confidence_score ?? 0;
786
+ const label = CLASS_NAMES[idx] ?? ('Kelas ' + idx);
787
+ const pct = (conf * 100).toFixed(2);
788
+ setResult('cnnVal',
789
+ `<span class="result-chip chip-green">✓ ${label}</span>` +
790
+ `<span style="margin-left:8px;font-size:12px;color:var(--gray-500);font-family:var(--font-mono)">${pct}% confidence</span>`
791
+ );
792
+ } catch (err) {
793
+ setResult('cnnVal', '⚠ Gagal: ' + err.message);
794
+ }
795
+
796
+ setLoading('btnCnn', false,
797
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><rect x="5" y="2" width="14" height="20" rx="2"/><line x1="9" y1="9" x2="15" y2="9"/><line x1="9" y1="13" x2="15" y2="13"/></svg> Daurin — Klasifikasi');
798
+ }
799
+
800
+ // ── K-MEANS ──
801
+ async function predictKMeans() {
802
+ const features = [
803
+ parseFloat(document.getElementById('km1').value),
804
+ parseFloat(document.getElementById('km2').value),
805
+ parseFloat(document.getElementById('km3').value),
806
+ parseFloat(document.getElementById('km4').value)
807
+ ];
808
+
809
+ setLoading('btnKmeans', true);
810
+ setResult('kmeansVal', 'Menghitung klaster...', true);
811
+
812
+ try {
813
+ const res = await fetch(API + '/predict-kmeans', {
814
+ method: 'POST',
815
+ headers: { 'Content-Type': 'application/json' },
816
+ body: JSON.stringify(features)
817
+ });
818
+ if (!res.ok) throw new Error('HTTP ' + res.status);
819
+ const data = await res.json();
820
+ const cluster = data.result?.assigned_cluster ?? 0;
821
+ const info = CLUSTER_MAP[cluster] ?? CLUSTER_MAP[0];
822
+ setResult('kmeansVal',
823
+ `<span class="result-chip ${info.chipClass}">● ${info.label}</span>` +
824
+ `<span style="margin-left:8px;font-size:12px;color:var(--gray-500);font-family:var(--font-mono)">Klaster #${cluster}</span>`
825
+ );
826
+ updateHexZone(info.hexColor, info.label);
827
+ } catch (err) {
828
+ setResult('kmeansVal', '⚠ Gagal: ' + err.message);
829
+ }
830
+
831
+ setLoading('btnKmeans', false,
832
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="3"/><path d="M5.6 5.6l1.4 1.4M16.6 16.6l1.4 1.4M5.6 18.4l1.4-1.4M16.6 7.4l1.4-1.4"/><circle cx="12" cy="12" r="8" stroke-dasharray="3 3"/></svg> Daurin — Clustering');
833
+ }
834
+
835
+ // ── REGRESSION ──
836
+ async function predictRegression() {
837
+ const features = [
838
+ parseFloat(document.getElementById('rg1').value),
839
+ parseFloat(document.getElementById('rg2').value),
840
+ parseFloat(document.getElementById('rg3').value)
841
+ ];
842
+
843
+ setLoading('btnReg', true);
844
+ setResult('regVal', 'Menghitung prediksi...', true);
845
+
846
+ try {
847
+ const res = await fetch(API + '/predict-regression', {
848
+ method: 'POST',
849
+ headers: { 'Content-Type': 'application/json' },
850
+ body: JSON.stringify(features)
851
+ });
852
+ if (!res.ok) throw new Error('HTTP ' + res.status);
853
+ const data = await res.json();
854
+ const val = data.result?.predicted_methane_value ?? 0;
855
+ setResult('regVal',
856
+ `<span class="result-chip chip-blue">◆ ${val.toFixed(4)} ton CH₄</span>` +
857
+ `<span style="margin-left:8px;font-size:12px;color:var(--gray-500);font-family:var(--font-mono)">per tahun</span>`
858
+ );
859
+ updateChart(val);
860
+ } catch (err) {
861
+ setResult('regVal', '⚠ Gagal: ' + err.message);
862
+ }
863
+
864
+ setLoading('btnReg', false,
865
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg> Daurin — Prediksi Metana');
866
+ }
867
+
868
+ // ── HEX GRID ──
869
+ function buildHex() {
870
+ const container = document.getElementById('hexContainer');
871
+ container.innerHTML = '';
872
+ const layout = [
873
+ { n: 5, colors: ['#22c55e','#22c55e','#eab308','#22c55e','#22c55e'] },
874
+ { n: 4, colors: ['#22c55e','#eab308','#22c55e','#ef4444'] },
875
+ { n: 5, colors: ['#22c55e','#22c55e','#22c55e','#eab308','#22c55e'] }
876
+ ];
877
+ const zones = { '#22c55e': 'Aman', '#eab308': 'Sedang', '#ef4444': 'Kritis' };
878
+
879
+ layout.forEach(row => {
880
+ const rowDiv = document.createElement('div');
881
+ rowDiv.className = 'hex-row';
882
+ row.colors.forEach(color => {
883
+ const cell = document.createElement('div');
884
+ cell.className = 'hex-cell';
885
+ cell.dataset.zone = zones[color];
886
+ cell.dataset.color = color;
887
+ cell.innerHTML = `<svg viewBox="0 0 28 24" xmlns="http://www.w3.org/2000/svg">
888
+ <polygon points="14,1 27,7 27,17 14,23 1,17 1,7" fill="${color}" stroke="white" stroke-width="1.2" rx="2"/>
889
+ </svg>`;
890
+ cell.addEventListener('mouseenter', showTip);
891
+ cell.addEventListener('mousemove', moveTip);
892
+ cell.addEventListener('mouseleave', hideTip);
893
+ rowDiv.appendChild(cell);
894
+ });
895
+ container.appendChild(rowDiv);
896
+ });
897
+ }
898
+
899
+ function showTip(e) {
900
+ const tip = document.getElementById('hexTip');
901
+ tip.innerHTML = `<strong>Zona ${e.currentTarget.dataset.zone}</strong><br/>Klik Daurin untuk update`;
902
+ tip.style.display = 'block';
903
+ moveTip(e);
904
+ }
905
+
906
+ function moveTip(e) {
907
+ const tip = document.getElementById('hexTip');
908
+ tip.style.left = (e.clientX + 12) + 'px';
909
+ tip.style.top = (e.clientY - 36) + 'px';
910
+ }
911
+
912
+ function hideTip() {
913
+ document.getElementById('hexTip').style.display = 'none';
914
+ }
915
+
916
+ function updateHexZone(color, label) {
917
+ const cells = document.querySelectorAll('.hex-cell');
918
+ const zones = { '#22c55e': 'Aman', '#eab308': 'Sedang', '#ef4444': 'Kritis' };
919
+ cells.forEach((cell, i) => {
920
+ if (i % 3 === 0) {
921
+ cell.dataset.zone = label;
922
+ cell.dataset.color = color;
923
+ cell.querySelector('polygon').setAttribute('fill', color);
924
+ }
925
+ });
926
+ }
927
+
928
+ // ── CHART ──
929
+ function initChart() {
930
+ const months = ['Jan','Feb','Mar','Apr','Mei','Jun','Jul','Agu','Sep','Okt','Nov','Des'];
931
+ const base = [38,42,47,44,55,60,57,65,69,66,71,78];
932
+ chartHistory = [...base];
933
+
934
+ const ctx = document.getElementById('methaneChart').getContext('2d');
935
+ chart = new Chart(ctx, {
936
+ type: 'line',
937
+ data: {
938
+ labels: months,
939
+ datasets: [
940
+ {
941
+ label: 'Historis',
942
+ data: base,
943
+ borderColor: '#16a34a',
944
+ backgroundColor: 'rgba(22,163,74,0.1)',
945
+ borderWidth: 2,
946
+ pointRadius: 3,
947
+ pointBackgroundColor: '#16a34a',
948
+ tension: 0.4,
949
+ fill: true
950
+ },
951
+ {
952
+ label: 'Prediksi',
953
+ data: base.map(v => +(v * 0.88).toFixed(1)),
954
+ borderColor: '#4ade80',
955
+ backgroundColor: 'transparent',
956
+ borderWidth: 1.5,
957
+ borderDash: [4, 3],
958
+ pointRadius: 2,
959
+ tension: 0.4,
960
+ fill: false
961
+ }
962
+ ]
963
+ },
964
+ options: {
965
+ responsive: true,
966
+ maintainAspectRatio: false,
967
+ plugins: {
968
+ legend: {
969
+ display: true,
970
+ position: 'top',
971
+ labels: { font: { size: 10, family: "'Space Mono', monospace" }, boxWidth: 10, padding: 8, color: '#6b7280' }
972
+ }
973
+ },
974
+ scales: {
975
+ x: {
976
+ ticks: { font: { size: 9, family: "'Space Mono', monospace" }, color: '#9ca3af' },
977
+ grid: { display: false }
978
+ },
979
+ y: {
980
+ ticks: { font: { size: 9, family: "'Space Mono', monospace" }, color: '#9ca3af' },
981
+ grid: { color: 'rgba(0,0,0,0.04)', lineWidth: 0.5 }
982
+ }
983
+ }
984
+ }
985
+ });
986
+ }
987
+
988
+ function updateChart(val) {
989
+ if (!chart) return;
990
+ chartHistory.push(val);
991
+ if (chartHistory.length > 12) chartHistory.shift();
992
+ chart.data.datasets[0].data = chartHistory;
993
+ chart.data.datasets[1].data = chartHistory.map(v => +(v * 0.88).toFixed(1));
994
+ chart.update('active');
995
+ }
996
+
997
+ // ── INIT ──
998
+ buildHex();
999
+ initChart();
1000
+ </script>
1001
+ </body>
1002
+ </html>
main.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File, HTTPException
2
+ import tensorflow as tf
3
+ import joblib
4
+ import numpy as np
5
+ from PIL import Image
6
+ import io
7
+
8
+ # 1. Inisialisasi Backend FastAPI dengan Dokumentasi Otomatis
9
+ app = FastAPI(
10
+ title="API Manajemen Sampah & TPA - 3 Model AI",
11
+ description="API tunggal untuk melayani 3 model AI: Klasifikasi Sampah (CNN), Clustering TPA (K-Means), dan Prediksi Emisi Metana (Linear Regression).",
12
+ version="1.0.0"
13
+ )
14
+
15
+ # 2. Status model disiapkan di awal agar endpoint bisa memberi respons jelas jika startup gagal
16
+ MODEL_CNN = None
17
+ MODEL_KMEANS = None
18
+ SCALER_TPA = None
19
+ MODEL_REGRESSION = None
20
+
21
+ # 3. Optimasi (Lazy Loading): Memuat semua file model dan scaler sekali saja di awal (Global Scope)
22
+ try:
23
+ MODEL_CNN = tf.keras.models.load_model("models/waste_classifier_cnn.h5")
24
+ MODEL_KMEANS = joblib.load("models/clustering_tpa_model.pkl")
25
+ SCALER_TPA = joblib.load("models/scaler_tpa.pkl")
26
+ MODEL_REGRESSION = joblib.load("models/methane_regression_model.pkl")
27
+ print("🚀 SUKSES: Semua 3 model AI dan Scaler berhasil dimuat ke memori server!")
28
+ except Exception as e:
29
+ print(f"❌ ERROR: Gagal memuat file model. Periksa folder 'models/'. Detail: {e}")
30
+
31
+
32
+ @app.get("/", tags=["Main Route"])
33
+ def root():
34
+ return {
35
+ "status": "Online",
36
+ "message": "API Layanan 3 Model AI (Sampah, TPA, & Metana) aktif dan siap digunakan!"
37
+ }
38
+
39
+
40
+ @app.get("/health", tags=["Main Route"])
41
+ def health_check():
42
+ models_loaded = all(
43
+ model is not None
44
+ for model in (MODEL_CNN, MODEL_KMEANS, SCALER_TPA, MODEL_REGRESSION)
45
+ )
46
+ return {
47
+ "status": "ok" if models_loaded else "degraded",
48
+ "models_loaded": models_loaded
49
+ }
50
+
51
+
52
+ # ================= MODEL 1: CNN (KLASIFIKASI JENIS SAMPAH) =================
53
+ @app.post("/predict-cnn", tags=["1. Waste Classification (CNN)"])
54
+ async def predict_cnn(file: UploadFile = File(...)):
55
+ """
56
+ Endpoint untuk mengklasifikasikan jenis sampah berdasarkan input gambar.
57
+ Menerima file gambar (.jpg / .png).
58
+ """
59
+ if file.content_type not in ["image/jpeg", "image/png"]:
60
+ raise HTTPException(status_code=400, detail="Format file tidak didukung. Harus berupa JPG atau PNG.")
61
+ if MODEL_CNN is None:
62
+ raise HTTPException(status_code=503, detail="Model CNN belum siap di server.")
63
+
64
+ try:
65
+ # Membaca data gambar yang diunggah
66
+ image_bytes = await file.read()
67
+ image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
68
+
69
+ # Pengujian & Pemrosesan Input: Ubah ukuran ke 150x150 sesuai spesifikasi training kamu
70
+ image = image.resize((150, 150))
71
+ image_array = np.array(image) / 255.0 # Normalisasi nilai pixel gambar
72
+ image_array = np.expand_dims(image_array, axis=0) # Ubah matriks dimensi menjadi (1, 150, 150, 3)
73
+
74
+ # Eksekusi Prediksi CNN
75
+ predictions = MODEL_CNN.predict(image_array)
76
+ pred_class = int(np.argmax(predictions, axis=1)[0])
77
+ confidence = float(np.max(predictions))
78
+
79
+ return {
80
+ "success": True,
81
+ "model_type": "Convolutional Neural Network (CNN)",
82
+ "result": {
83
+ "predicted_class_index": pred_class,
84
+ "confidence_score": round(confidence, 4)
85
+ }
86
+ }
87
+ except Exception as e:
88
+ raise HTTPException(status_code=500, detail=f"Gagal memproses gambar pada model CNN: {str(e)}")
89
+
90
+
91
+ # ================= MODEL 2: K-MEANS (CLUSTERING TPA) =================
92
+ @app.post("/predict-kmeans", tags=["2. TPA Clustering (K-Means)"])
93
+ def predict_kmeans(features: list[float]):
94
+ """
95
+ Endpoint untuk melakukan clustering/pengelompokan kondisi TPA.
96
+ Masukkan data array numerik linear (fitur) sesuai dengan variabel saat training.
97
+ Contoh JSON Input Body: [0.45, 1.2, 3.44, 0.12]
98
+ """
99
+ try:
100
+ if MODEL_KMEANS is None or SCALER_TPA is None:
101
+ raise HTTPException(status_code=503, detail="Model K-Means atau scaler belum siap di server.")
102
+ # Konversi list data input menjadi array 2D
103
+ data_array = np.array([features])
104
+
105
+ # Pengujian Input: Lakukan transformasi normalisasi menggunakan Scaler bawaan training
106
+ scaled_data = SCALER_TPA.transform(data_array)
107
+
108
+ # Eksekusi Prediksi Cluster K-Means
109
+ assigned_cluster = int(MODEL_KMEANS.predict(scaled_data)[0])
110
+
111
+ return {
112
+ "success": True,
113
+ "model_type": "K-Means Clustering",
114
+ "result": {
115
+ "assigned_cluster": assigned_cluster
116
+ }
117
+ }
118
+ except Exception as e:
119
+ raise HTTPException(status_code=400, detail=f"Format input salah atau jumlah fitur tidak cocok dengan scaler/model: {str(e)}")
120
+
121
+
122
+ # ================= MODEL 3: LINEAR REGRESSION (PREDIKSI GAS METANA) =================
123
+ @app.post("/predict-regression", tags=["3. Methane Emission Prediction (Linear Regression)"])
124
+ def predict_regression(features: list[float]):
125
+ """
126
+ Endpoint untuk memprediksi volume emisi gas metana secara kontinu.
127
+ Masukkan data fitur angka numerik linier sebagai input.
128
+ Contoh JSON Input Body: [25.5, 400.0, 12.3]
129
+ """
130
+ try:
131
+ if MODEL_REGRESSION is None:
132
+ raise HTTPException(status_code=503, detail="Model regresi belum siap di server.")
133
+ # Konversi input list menjadi array 2D untuk scikit-learn
134
+ data_array = np.array([features])
135
+
136
+ # Eksekusi Prediksi Linear Regression
137
+ regression_result = MODEL_REGRESSION.predict(data_array)
138
+ predicted_value = float(regression_result[0])
139
+
140
+ return {
141
+ "success": True,
142
+ "model_type": "Linear Regression",
143
+ "result": {
144
+ "predicted_methane_value": round(predicted_value, 4)
145
+ }
146
+ }
147
+ except Exception as e:
148
+ raise HTTPException(status_code=400, detail=f"Format input salah atau tidak sesuai dengan model regresi: {str(e)}")
models/clustering_tpa_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:240350a4c6ff8874b57f0e08c37eabe64633ac2488cb990232e751a21581f650
3
+ size 955
models/methane_regression_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f265709cc1668c97a5149448eeed960955042508f9a4c82b5365f0d2fa3bdf0a
3
+ size 785
models/scaler_tpa.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45571f3737f670eb6165a7fef4b269b7d08330274d582d49b40de9071da8be1d
3
+ size 1591
models/waste_classifier_cnn.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41de14e439602a095314cc983640417e9b883f7b5321d0e33f9086e8628eac43
3
+ size 267023136
render.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ services:
2
+ - type: web
3
+ name: daurin-ai-hub
4
+ env: docker
5
+ plan: free
6
+ healthCheckPath: /health
7
+ autoDeploy: true
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn[standard]