This project is a FastAPI-based application for predicting body fat percentage. It includes a web form for manual input and a REST API for external integration.
Before running, ensure you have Docker and Docker Compose installed.
Run the following command for the first time (to build the images):
docker-compose up --buildFor subsequent runs, use:
docker-compose upThis will start the FastAPI service inside a Docker container.
If you pull updates from GitHub that affect the API service, rebuild the Docker containers:
docker-compose up --buildThis ensures your application is updated with the latest changes.
Once the application is running, go to:
Use the web interface to input body measurements and get predictions.
FastAPI provides an interactive Swagger UI for API testing:
This allows you to test API requests directly from the browser.
You can use curl or any HTTP client (like Postman) to send requests to the API.
curl -X POST "http://localhost:8000/predict/" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "abdomen=23&hip=23&weight=23&thigh=23&knee=23&biceps=3&neck=23"{
"prediction": -23.959071614389472
}You can modify the parameters (abdomen, hip, weight, etc.) to get different predictions.
To run the containers in the background, use:
docker-compose up -dTo stop running containers:
docker-compose downTo list all running containers:
docker psTo debug issues or see FastAPI logs:
docker-compose logs -fdocker-compose restartBy default, the API is only available locally. To expose it to the outside world, make sure your server’s firewall allows traffic on port 8000.
Modify the docker-compose.yml file to ensure the service listens on all interfaces:
ports:
- "8000:8000"Then restart the container:
docker-compose down
docker-compose up -dNow, the API should be accessible from other devices via:
🔗 http://YOUR_SERVER_IP:8000
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Returns the web form |
| POST | /predict/ |
Sends body measurements and returns a body fat prediction |
Try:
docker-compose down
docker system prune -a
docker-compose up --buildCheck container logs:
docker-compose logs -fEnsure port 8000 is not blocked by a firewall.
✅ Add frontend styling for a better UI.
✅ Deploy the API to a cloud server.
✅ Integrate with a database for storing past predictions.
Feel free to fork this project and submit a pull request. If you find a bug or have a feature request, open an issue.
🚀 Happy Coding! 🚀