This project is an API that uses a demand prediction model to predict the demand for Tap30 service. The API is implemented using FastAPI framework.
- Python 3.8+
- Required libraries:
- FastAPI
- Uvicorn
- XGBoost (for the model)
- joblib
- numpy
- mysql-connector-python (for MariaDB connection)
To set up the project and install required libraries, follow these steps:
-
Create a virtual environment (optional):
python -m venv venv
-
Activate the virtual environment:
- For Windows:
.\venv\Scripts\activate
- For macOS/Linux:
source venv/bin/activate
- For Windows:
-
Install required libraries:
pip install fastapi uvicorn joblib numpy scikit-learn mysql-connector-python
-
Place your trained model file (
model.joblib) in the project directory.
To start the server, use the following command:
uvicorn main:app --reloadThe server will now be running at http://127.0.0.1:8000.
To send data to the API and get predictions, you can use tools like Postman or curl.
- URL:
http://127.0.0.1:8000/predict - Method:
POST - Request body (JSON):
{ "day": 100, "hour": 8, "row": 2, "col": 6, }
On success, the response will look like this:
{
"input_features": {
"day": 100,
"hour": 8,
"row": 2,
"col": 6,
},
"predicted_demand": 50
}If the input data is missing required fields, the API will return an error message. For example, if a required field is missing:
{
"detail": [
{
"loc": ["body", "day"],
"msg": "Field required",
"type": "missing"
},
{
"loc": ["body", "hour"],
"msg": "Field required",
"type": "missing"
}
]
}-
If you are using MariaDB to store data, you need to configure the database connection details in the
main.pyfile. -
This project is set up to run locally, but you can deploy it on a server or platforms like Heroku or AWS for production use.
main.py: FastAPI code for processing the prediction and returning results.model.joblib: The trained model file saved using XGBoost or any other model you have used.requirements.txt: A list of Python dependencies for quick installation.
- If you have any suggestions or issues, feel free to open an issue on the GitHub repository.
- Contributions to the development of this project are welcome.

