Sign In

Here's how to use the best Faceswap model for personalization

2
Here's how to use the best Faceswap model for personalization

Introduction

If you’ve ever wanted to switch faces with a friend, family member, or a complete stranger, the possibilities are now available and easier to access than ever before. Fortunately, that's what we will be doing. In this article, we will jump straight into the face swap creation process with no further delay!

For this, we will be using HTTPs call.

Before we proceed, here are some important things to take note of:

  • Seek permission before face swapping someone else's face

  • Do not spread harmful or illicit contents

Now let's get to the meat of this tutorial!

Step 1: Generate a task_id in the Faceswap endpoint.

This is where we will generate a task_id with the input of the images.

Do note that:

  • Each image must only contain one visible face.

  • "target_image" refers to the face in this image being swapped out

  • "swap_image" refers to the face in this image being swapped onto "target_image"

POST /api/face_swap/v1/async HTTP/1.1
X-Api-Key: {{x-api-key}}                      //Insert your API Key
Content-Type: application/json
Accept: application/json
Host: api.piapi.ai
Content-Length: 101
{
  "target_image": "image1.png",               //Replace "image1.png" with your image
  "swap_image": "image2.png",                 //Replace "image1.png" with your image
  "result_type": "url"
}

Step 2: Response

After sending in the request, keep the returned task_id located in the response terminal for the next step.

{
  "code": 200,
  "data": {
    "task_id": "5b6ae******************a7011b92"  //Keep the task_id for later use
  },
  "message": "success"
}

Step 3: Fetching the Faceswap task_id

In the fetch endpoint, insert the returned task_id that you kept from the previous step into the task_id input field then send the request.

POST /api/face_swap/v1/fetch HTTP/1.1
X-Api-Key: {{x-api-key}}
Content-Type: application/json
Accept: application/json
Host: api.piapi.ai
Content-Length: 54
{
  "task_id": "5b6ae3177************1637a7011b92"          //Insert the task_id here
}

Step 4: Retrieving the result

Regarding the output response of the fetch endpoint, you may refer to their documentation for more information.

In the response terminal, copy the link of the image into a web browser and you should see your face swapped image!

Sample images

Let's take a look at what it looks like!

Here are the original images:



Here is the face swapped image:

The picture above is generated using PiAPI's Faceswap API model.

2

Comments