Implement a pipeline¶
This tutorial shows how to implement a Pipeline in the Swiss AI Center project step by step. It will guide you through the process of creating a Pipeline to detect faces in an image and blur them.
Tutorial¶
Prerequisites¶
To follow this tutorial, you need to have the following tools installed:
- Python 3.10
- An IDE (e.g. Visual Studio Code)
Prepare the Core Engine¶
To implement a Pipeline, you need to have a running Core Engine. If you don't have one, you can follow the Core Engine documentation.
Run the Webapp
For a better experience you can run the webapp by following the webapp reference documentation.
Prepare the services¶
The first step is to prepare the services that will be used in the Pipeline. In this tutorial, we will use the following services:
Launch the services¶
If the services are not running you can follow the explanations in the reference documentation to start them.
Create the pipeline¶
The Pipeline is created by posting a JSON object to the /pipelines
endpoint of the Core Engine. Create a file named face-blur-pipeline.json
in your IDE with the following code:
Note
You can find the slug of your services by going to the FastAPI documentation of the running Core Engine and use the /services
endpoint. You will find the slug of your services in the response.
What we just did is to create a Pipeline with two steps. The first step is the face detection service and the second step is the image blur service. The second step will only be executed if the first step detects at least one face. The Pipeline will take an image as input and return an image as output.
The inputs of each step are the outputs of the previous steps. The first step takes the pipeline's image as input and the second step takes the Pipeline's image and the result of the face detection as input.
Note
The identifier
field of each step is the name of the step in the Pipeline. It is used to reference the step in the needs
and inputs
fields.
Post the pipeline¶
Now that we have our Pipeline, we can post it to the Core Engine. To do so, go to the FastAPI documentation of the running Core Engine and use the /pipelines
endpoint to post the Pipeline by clicking on the Try it out
button
Simply copy the content of the face-blur-pipeline.json
file and paste it in the body
field of the /pipelines
endpoint and click on the Execute
button.
You should receive a 200
response with the Pipelineine you just posted.
Run the pipeline¶
You can run the pipeline using the FastAPI Swagger interface or by using the Webapp.
Using the FastAPI Swagger interface¶
Now that we have our Pipeline, we can run it. To do so, go to the FastAPI documentation of the running Core Engine and you should see the Pipeline you just posted in the Registered pipelines
endpoint with the slug /face-blur
.
Click on the Try it out
button, add an image to the body and click on the Execute
button.
You should receive a 200
response with a Pipeline Execution
object in the response body. This object contains the id of the execution and the tasks that will be executed.
You can check the status of the execution by checking the status of the last task with the /tasks/{task_id}
endpoint. You can find the id of the last task in the tasks
array of the Pipeline execution object.
Once the status of the last task is finished
, you can download the result by copying the data_out file keys and use them with the /storage/{key}
endpoint.
If the picture you provided had a face, the result should be blurred.
Using the Webapp¶
You can also run the Pipeline using the Webapp. To do so, go to the Webapp in your browser and find the Pipeline you just posted in the Pipelines
section.
Click on the VIEW
button and you should see the Pipeline as a Flow.
Click on the UPLOAD
button and upload an image. Now you can click on the RUN
button and the Pipeline will be executed. When the Pipeline is finished, you can download the result by clicking on the DOWNLOAD
button that will be enabled.
If the picture you provided had a face, the result should be blurred.
Congratulations!
You have successfully created a Pipeline locally. Now, you can use the same process to create a Pipeline on the Core Engine deployed on the cloud.