Spaces:
Running
Running
metadata
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
# 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.tflitebatik_classes_mobilenet_ultimate.jsonbatik_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
python app.py
Server akan berjalan di: http://localhost:5000
π API Endpoints
GET /
Get API information
Response:
{
"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:
curl -X POST http://localhost:5000/predict \
-F "image=@path/to/batik.jpg"
Example using 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:
{
"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:
{
"success": true,
"total": 20,
"classes": [
"batik-bali",
"batik-betawi",
"batik-celup",
...
]
}
GET /info
Get model information
Response:
{
"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:
{
"status": "healthy",
"model_loaded": true
}
π§ͺ Testing
Run test script:
# Test endpoints
python test_api.py
# Test with image prediction
python test_api.py path/to/batik.jpg
π¦ Deployment
Docker (Recommended)
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:
docker build -t batik-classifier-api .
docker run -p 5000:5000 batik-classifier-api
Heroku
# Login
heroku login
# Create app
heroku create batik-classifier-api
# Deploy
git push heroku main
Railway / Render
- Connect GitHub repository
- Set build command:
pip install -r requirements.txt - Set start command:
python app.py - Deploy
π§ Configuration
Environment variables:
FLASK_ENV=production # production or development
PORT=5000 # Server port
π 20 Batik Classes
- batik-bali
- batik-betawi
- batik-celup
- batik-cendrawasih
- batik-ceplok
- batik-ciamis
- batik-garutan
- batik-gentongan
- batik-kawung
- batik-keraton
- batik-lasem
- batik-megamendung
- batik-parang
- batik-pekalongan
- batik-priangan
- batik-sekar
- batik-sidoluhur
- batik-sidomukti
- batik-sogan
- batik-tambal
π€ Support
For issues or questions:
π License
MIT License - feel free to use for commercial or personal projects.
Made with β€οΈ by Maftuuh1922