Stuntify API is a specialized backend service designed to bridge the gap between raw health data and actionable stunting diagnostics.
It isn't just a script; it's the intelligent engine working behind the scenes. While the frontend handles the looks, this API handles the thinking. Unlike simple model wrappers, this project implements a complete MLOps Inference Pipeline. It intelligently orchestrates distinct serialized artifacts (Encoders, Scalers, Models) to ensure that every prediction request undergoes the exact same rigorous preprocessing as the training phase.
The system acts as a centralized inference unit. It doesn't just "guess"; it reconstructs the mathematical environment by synchronizing 4 key artifacts:
- Gender Encoder: Translates human categories (
Laki-laki) into machine vectors. - Standard Scaler: Normalizes anthropometric data (
Age,Height,Weight) to the model's expected distribution. - Classifier Model: The core logic engine trained for high accuracy.
- Target Decoder: Translates the math result back to a human-readable label (e.g.,
Severely Stunted).
- Schema Validation: Strictly enforces JSON structure to prevent garbage-in-garbage-out.
- Smart Error Handling: Catches edge cases (missing keys, wrong types) and returns meaningful HTTP 400 errors instead of crashing the server.
- Cross-Origin Ready: Fully configured with Flask-CORS to serve requests from any device—be it a Web App, Mobile Phone, or IoT Device.
- Core: Python 3.9+
- Service: Flask (Microframework)
- Computation: NumPy, Scikit-Learn, Joblib
- Security: Flask-CORS (Cross-Origin Resource Sharing enabled)
Most tutorials just load a model. This project ensures data consistency through a strict lifecycle for every request:
- Ingestion: The API receives raw JSON data:
{"jenis_kelamin", "umur", "tinggi", "berat"}. - Context Reconstruction: It loads the synchronized artifacts (Encoder, Scaler, Classifier, Decoder).
- Processing: The raw data flows through the pipeline:
Input Validated -> Gender Encoded -> Metrics Scaled -> Predicted -> Label Decoded
- Response: The final output is packaged as clean JSON for the client.
To talk to Stuntify, send a POST request to /predict.
1. The Request (What you send):
{
"jenis_kelamin": "Laki-laki",
"umur": 24,
"tinggi": 85.5,
"berat": 10.1
}2. The Response (What you get):
{
"prediction": "Severely Stunted"
}-
Clone the Repository
git clone https://github.com/viochris/API-Stuntify.git cd API-Stuntify -
Install Dependencies
pip install -r requirements.txt
-
Run the Server Execute the main script directly:
python api_predict.py
Output:
Running on http://127.0.0.1:5000 -
Consume Endpoint Send the POST request described in the Integration Guide above to
http://127.0.0.1:5000/predict.
Author: Silvio Christian, Joe "Code that speaks JSON, Logic that saves lives."