File size: 4,320 Bytes
7fdd922
 
 
 
 
 
 
 
 
 
aa5c395
 
7fdd922
aa5c395
 
7fdd922
 
 
aa5c395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fdd922
aa5c395
7fdd922
 
 
aa5c395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
---
title: Batik Classifier
emoji: 🎨
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
---

# 🎯 Batik Classifier API

REST API untuk klasifikasi motif batik menggunakan **MobileNetV2 + TFLite** dengan akurasi tinggi.

## πŸ“Š Model Info
- **Model**: MobileNetV2 (TFLite)
- **Classes**: 42 motif batik Indonesia
- **Input Size**: 224x224 RGB

## πŸš€ Quick Start

### 1. Setup Environment

```bash
# Buat virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# atau
venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt
```

### 2. Model Files

Model files sudah tersedia di folder `models/`:
- `batik_model.tflite`
- `batik_classes_mobilenet_ultimate.json`
- `batik_model_metadata.pkl`

```
batik-classifier/
└── api/
    β”œβ”€β”€ app.py
    β”œβ”€β”€ requirements.txt
    β”œβ”€β”€ test_api.py
    └── models/
        β”œβ”€β”€ batik_knn_model_95acc.pkl
        β”œβ”€β”€ batik_classes.pkl
        └── batik_model_metadata.pkl
```

### 3. Run Server

```bash
python app.py
```

Server akan berjalan di: `http://localhost:5000`

## πŸ“‹ API Endpoints

### GET `/`
Get API information

**Response:**
```json
{
  "message": "Batik Classifier API",
  "version": "1.0",
  "model": "InceptionV3 + KNN",
  "accuracy": "95.00%",
  "classes": 20
}
```

### POST `/predict`
Predict batik motif from image

**Request:**
- Method: POST
- Content-Type: multipart/form-data
- Body: `image` (file)

**Example using curl:**
```bash
curl -X POST http://localhost:5000/predict \
  -F "image=@path/to/batik.jpg"
```

**Example using Python:**
```python
import requests

with open('batik.jpg', 'rb') as f:
    files = {'image': f}
    response = requests.post('http://localhost:5000/predict', files=files)
    print(response.json())
```

**Response:**
```json
{
  "success": true,
  "prediction": "batik-parang",
  "confidence": 0.95,
  "percentage": "95.00%",
  "top_5_predictions": [
    {
      "class": "batik-parang",
      "confidence": 0.95,
      "percentage": "95.00%"
    },
    {
      "class": "batik-kawung",
      "confidence": 0.03,
      "percentage": "3.00%"
    }
  ]
}
```

### GET `/classes`
Get list of all batik classes

**Response:**
```json
{
  "success": true,
  "total": 20,
  "classes": [
    "batik-bali",
    "batik-betawi",
    "batik-celup",
    ...
  ]
}
```

### GET `/info`
Get model information

**Response:**
```json
{
  "success": true,
  "model_info": {
    "accuracy": "95.00%",
    "model_type": "InceptionV3 + KNN",
    "n_classes": 20,
    "total_training_data": 17000,
    "trained_date": "2025-12-07 11:41:28"
  }
}
```

### GET `/health`
Health check endpoint

**Response:**
```json
{
  "status": "healthy",
  "model_loaded": true
}
```

## πŸ§ͺ Testing

Run test script:
```bash
# Test endpoints
python test_api.py

# Test with image prediction
python test_api.py path/to/batik.jpg
```

## πŸ“¦ Deployment

### Docker (Recommended)

```dockerfile
FROM python:3.10-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["python", "app.py"]
```

Build and run:
```bash
docker build -t batik-classifier-api .
docker run -p 5000:5000 batik-classifier-api
```

### Heroku

```bash
# Login
heroku login

# Create app
heroku create batik-classifier-api

# Deploy
git push heroku main
```

### Railway / Render

1. Connect GitHub repository
2. Set build command: `pip install -r requirements.txt`
3. Set start command: `python app.py`
4. Deploy

## πŸ”§ Configuration

Environment variables:
```bash
FLASK_ENV=production  # production or development
PORT=5000             # Server port
```

## πŸ“ 20 Batik Classes

1. batik-bali
2. batik-betawi
3. batik-celup
4. batik-cendrawasih
5. batik-ceplok
6. batik-ciamis
7. batik-garutan
8. batik-gentongan
9. batik-kawung
10. batik-keraton
11. batik-lasem
12. batik-megamendung
13. batik-parang
14. batik-pekalongan
15. batik-priangan
16. batik-sekar
17. batik-sidoluhur
18. batik-sidomukti
19. batik-sogan
20. batik-tambal

## 🀝 Support

For issues or questions:
- GitHub: https://github.com/Maftuuh1922/warisan-digital
- Email: rizkiuya12@gmail.com

## πŸ“„ License

MIT License - feel free to use for commercial or personal projects.

---

**Made with ❀️ by Maftuuh1922**