This GitHub repo is set up for the development of a Docker-based service on the QSPRpred tool github.com/CDDLeiden/QSPRpred. In the initial stage, the service will have prediction functionalities based on imported, pre-trained model(s).
This guide covers the setup and usage of a Flask application for predictions via a Docker container. The application provides both a user interface for interacting with the model and an API for programmatic access.
To build the Docker image for the Flask application, use the following command:
docker build -t qspr_flask_image -f Dockerfile .
Run the Docker container with the following command. This command also mounts a local directory to the container to make model files accessible:
docker run -d -p 5000:5000 --name qspr_flask_container -v $(pwd)/models:/usr/src/app/models qspr_flask_image
Once the container is running, navigate to http://localhost:5000 in your web browser. You will see the Flask application interface which allows you to:
- Select one or more prediction models.
- Input multiple SMILES strings either through a text box or by uploading a CSV file (e.g. the smiles_sample.csv).
- Download the prediction results in various formats, or generate a report.
You can also interact with the Flask application via its API from your coding environment. Below are examples of how to use the API:
To initiate a prediction and receive the results in JSON format, use:
curl -X POST localhost:5000/api -H "Content-Type: application/json" -d '{
"smiles": ["C1=CC=CC=C1C(=O)NC2=CC=CC=C2", "CC(=O)OC1=CC=CC=C1C(=O)O"],
"models": ["P10827_RF_Model", "P10828_RF_Model"],
"format": "text"
}'
To receive the prediction results as a CSV file, use:
curl -X POST localhost:5000/api -H "Content-Type: application/json" -d '{
"smiles": ["C1=CC=CC=C1C(=O)NC2=CC=CC=C2", "CC(=O)OC1=CC=CC=C1C(=O)O"],
"models": ["P10827_RF_Model", "P10828_RF_Model"],
"format": "csv"
}' -o predictions.csv