API For Multiple Face Swap
June 18, 2024About 2 min
API For Multiple Face Swap
Considerations
- Before using the API, make sure you have obtained the API key. Refer to the link below for instructions on how to obtain it. API For API Key Settings
- All generated images will be automatically deleted after 24 hours. Please make sure to save the images you need to your local storage in a timely manner.
- Detect Job
- Swap Job
Header Attributes
Parameter | Description |
---|---|
Authorization | Your API Key used for request authorization. |
Using Tutorials
Step 1: Detect Faces in the Image
Call the create-detect
API to Obtain Face Coordinates in the Image
- First, use the
create-detect
API to detect faces in the image and obtain their coordinates.
import requests
url = 'https://developer.remaker.ai/api/remaker/v1/face-detect/create-detect'
headers = {
'accept': 'application/json',
'Authorization': 'your api-key',
}
files = {
'target_image': open('demo1.jpg', 'rb')
}
response = requests.post(url, headers=headers, files=files)
print(response.json())
{
"code": 100000,
"result": {
"job_id": "8cfe5bac-3208-4384-83c2-4fa46f2ce22a"
},
"message": {
"en": "Request Success."
}
}
- Then, call the query task interface to check the task status. When the task is completed, you will receive the following result:
import requests
url = 'https://developer.remaker.ai/api/remaker/v1/face-detect/face-detect/a4274b95-31d0-4cca-8a84-8c328f6b4ace'
headers = {
'accept': 'application/json',
'Authorization': 'your token',
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print(data)
else:
print(f"error: {response.status_code}")
{
"code": 100000,
"result": {
"output_image_url": [
[
[
192.2239532470703,
124.05651092529297,
307.34918212890625,
292.75439453125
],
[
276.0821228027344,
264.65228271484375,
380.96917724609375,
397.80316162109375
]
]
],
"input_image_url": [
"https://image.remaker.ai/datarm/api/face-detect/2024-07-29/input/8cfe5bac-3208-4384-83c2-4fa46f2ce22a_original_.png"
],
"job_id": "8cfe5bac-3208-4384-83c2-4fa46f2ce22a",
"message": ""
},
"message": {
"en": "Image generated successfully."
}
}
Step 2: Cut faces based on coordinates
Determine the location of the face in the image based on the coordinates returned in the first step
- Utilize the face coordinates returned in Step 1 to determine the positions of each face in the image.
Step 3: Replace Faces
Replace Faces in the Image, and package the Replaced Faces into a ZIP File
- Replace the faces in the image as needed, following the sequence determined in Step 2,,If you do not want to replace the face, please upload the original face.
- Package the replaced face images into a ZIP file for further processing and transmission.
Step 4: Swap Faces
Call the create-swap
API to Perform Face Swapping
- Use the
create-swap
API to perform the face swapping operation on the replaced images.
import requests
url = 'https://developer.remaker.ai/api/remaker/v1/face-detect/create-swap'
headers = {
'accept': 'application/json',
'Authorization': 'your api-key',
}
files = {
'target_image': open('demo1.jpg', 'rb') # Face to be replaced(binary )
'model_face': open('demo1.zip', 'rb') # Your Face(zip binary )
}
response = requests.post(url, headers=headers, files=files)
print(response.json())
{
"code": 100000,
"result": {
"job_id": "c2091af8-63a8-4e45-95b2-28291e971877"
},
"message": {
"en": "Request Success."
}
}
- Then call the query task interface to check the status of the task. When the task is completed, you will receive the following result:
import requests
url = 'https://developer.remaker.ai/api/remaker/v1/face-detect/face-detect/a4274b95-31d0-4cca-8a84-8c328f6b4ace'
headers = {
'accept': 'application/json',
'Authorization': 'your token',
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print(data)
else:
print(f"error: {response.status_code}")
{
"code": 100000,
"result": {
"output_image_url": [
"https://image.remaker.ai/datarm/api/face-detect/2024-07-29/output/tmp3mokr1zz.png"
],
"input_image_url": [
"https://image.remaker.ai/datarm/api/face-detect/2024-07-29/input/c2091af8-63a8-4e45-95b2-28291e971877_original_.png"
],
"job_id": "c2091af8-63a8-4e45-95b2-28291e971877",
"message": ""
},
"message": {
"en": "Image generated successfully."
}
}