NiaAML API is a Python library for using NiaAML as an FastAPI based web API. The currently used version of NiaAML is 2.1.0.
- Download project
- Install dependencies with Poetry
poetry install
- Navigate to project folder and run server in terminal.
bash uvicorn main:app --reload
or- run the
main.py
script of the project
- Run server
- Navigate to Swagger docs to see how to use.
-
Use the official image from DockerHub repository (alenrajsp/niaamlapi:0.2)[https://hub.docker.com/r/alenrajsp/niaamlapi]
-
Run from terminal with
docker run -p <PORT>:80 alenrajsp/niaamlapi:main
. The <PORT> variable is the port from which you want to access the container. -
If data is to be preserved the /src/data folder needs to be made into a volume. The data folder contains the following subfolders and files:
Folder / file | Description |
---|---|
/csvfiles | Folder where all uploaded csv files are saved. |
/pipelineResults | Folder where .ppln and .txt files of results are saved |
jobs.db | SQLite3 database where all executed and current jobs are saved. |
jobs.db | SQLite3 database where all job queues are saved. |
Only CSV type pipelines from NiaAML are currently supported. To create a remote job call the /pipeline/uploadCsv method. Upload a csv file (with last column of the CSV file as a class). The method returns a uuid which is needed in the next step.
To run the pipeline you need to call the /pipeline/run method. The data_id parameter represents the uuid returned from the CSV upload method.
To execute the example shown in NiaAML documentation the following request is needed.
POST http://localhost:8000/pipeline/run?data_id=50e7e53e-f85c-4361-b52a-a31422719743
REQUEST BODY: {
"web_pipeline_optimizer": {
"classifiers": [
"AdaBoost"
],
"feature_selection_algorithms": [
"SelectKBest"
],
"feature_transform_algorithms": [
"Normalizer"
],
"categorical_features_encoder": "OneHotEncoder",
"imputer": "SimpleImputer",
"log": false,
"log_verbose": false,
"log_output_file": ""
},
"web_pipeline_optimizer_run": {
"fitness_name": "Accuracy",
"pipeline_population_size": 5,
"inner_population_size": 5,
"number_of_pipeline_evaluations": 5,
"number_of_inner_evaluations": 5,
"optimization_algorithm": "ParticleSwarmAlgorithm",
"inner_optimization_algorithm": "ParticleSwarmAlgorithm"
}
}
The returned response should look something like:
{
"file_id": "2e4b64b1-e192-4f24-b5c7-045bb51aee67",
"result": "Added to queue!",
"export": "85486cf6-f760-4556-9f73-460c1aa0b80d"
}
Where the export attribute is the input parameter for the data_id of /pipeline/export methods, since more than one pipeline can be created from a CSV file.
Once jobs are completed the .ppln and .txt files can be retrieved using the following two requests:
.txt result files - *note data_id = export value of /pipeline/run method.
POST http://localhost:8000/pipeline/export/text?data_id=50e7e53e-f85c-4361-b52a-a31422719743
.ppln result files
POST http://localhost:8000/pipeline/export/ppln?data_id=50e7e53e-f85c-4361-b52a-a31422719743
All of the endpoints have functional tests available for them in the tests directory. You can also check the tests to better understand how to make requests with the client.