Local Inpainting

Description

This API is used to process requests for AI local content generation in the cloud. Please refer to the following documentation for details of the specific effects.

Image Examples

Input ImageOutput Image
SampleResult

Image Requirements

Image formats: JPG, PNG

Invocation Information

Task submission endpoint: https://openapi.meitu.com/api/v1/sdk/sync/push
Task name (task): /v1/InPainting/468520
Task type (task_type): formula

Permissions

Open Platform API Signature

Request Parameters

RequiredParameter NameTypeParameter Description
YesparamsstringInference parameters
Yesinit_imagesobject[]Image parameters. Two images must be provided: the first is the original image, and the second is the mask image (selecting the area to be painted)
YestaskstringFixed: /v1/InPainting/468520
Yestask_typestringFixed: formula
Nosync_timeoutintDefault is 30. -1 means no waiting. This is the synchronous timeout. When the API times out, status returns 9. Use the (https://meituhub.cn/docs?id=179&f_id=11) API to query
Norsp_media_typestring“jpg”: the fused result image is returned directly as base64-encoded data
“url”: the fused result image is returned directly as a URL; URL is returned by default

init_images image parameters are structured as follows

RequiredParameter NameTypeParameter Description
YesurlstringImage URL
NoprofileobjectMultimedia parameters

profile parameters are structured as follows

RequiredParameter NameTypeParameter Description
Nomedia_extraobjectAdditional multimedia parameters
Nomedia_profilesobjectMultimedia description

media_profiles parameters are structured as follows

RequiredParameter NameTypeParameter Description
Nomedia_data_typestring"url": the multimedia file is transmitted as a URL,
"jpg": the multimedia file is transmitted as base64-encoded data

Parameter description in params (must be escaped as a string)

RequiredParameter NameTypeParameter Description
YesparameterStringInpainting parameters

Parameter description in parameter

RequiredParameter NameTypeParameter Description
Norsp_media_typeString“jpg”: the fused result image is returned directly as base64-encoded data; “url”: the fused result image is returned directly as a URL
Noprompt_posStringPositive prompt
NoseedintRandom seed [-1,2147483647]. If not provided, the seed value is generated randomly
Noreturn_format_typeStringReturned image format. Default is ‘png’. Options: [‘jpeg’, ‘jpg’, ‘png’, ‘webp’]. Any other input returns ‘png’ format.

Input Example

{
    "params": "{\"parameter\":{\"rsp_media_type\":\"url\",\"prompt_pos\":\"lipstick lying on satin fabric\"}}",
    "init_images": [
        {
            "profile": {
                "media_profiles": {
                    "media_data_type": "url"
                },
                "version": "v1"
            },
            "url": "Original Image URL or Base64"
        },
        {
            "profile": {
                "media_profiles": {
                    "media_data_type": "url"
                },
                "version": "v1"
            },
            "url": "Mask URL or Base64"
        }
    ],
    "task": "/v1/InPainting/468520",
    "task_type": "formula"
}

Response Description

Successful Response Description

FieldTypeParameter Description
media_info_listListEach item contains multimedia information (for example, image data and corresponding information), same as above
parameterObjectReturned information type identifier

 

Field description for a single element in media_info_list

FieldTypeParameter Description
media_dataStringBase64-encoded multimedia file data
media_profilesObjectDescription of multimedia file-related attribute information

Field description in parameter

FieldTypeParameter Description
rsp_media_typeString'jpg' indicates that media_data is an image compressed and encoded with base64

 

Field description in media_profiles

FieldTypeParameter Description
media_data_typeString'jpg' indicates that media_data is an image compressed and encoded with base64

Failed Response Description

FieldTypeDescription
ErrorCodeIntError code
ErrorMsgStringError message
DataStringExample of the returned detailed information value

Response Examples

Successful Response Example

Response Status: 200

content-type is application/json; charset=utf-8

{
    "parameter": {
        "rsp_media_type": "jpg",
   }
	"media_info_list": [{
		"media_data": "...",
		"media_profiles": {
			"media_data_type": "jpg"
		}
	}]
}

Failed Response Example

Response Status: 400

content-type is application/json; charset=utf-8

{
	"ErrorCode": 20003, 
	"ErrorMsg": "detect no face", 
	"Data": null
}

Error Codes and Messages Specific to the Current API

ErrorCode Status CodeError MessageDescription
20001PROCESS_ERRORProcessing error
20003DETECT_NOT_FACEFace missing
20004MORE_THAN_ONE_FACEMore than one face
20007MISSING_LANDMARK_ARGUMENTSFace landmarks were not provided
20008UNSUITABLE_IMAGEImage does not meet the requirements
20009UNSUPPORT_TYPEUnsupported type
20010DETECT_NOT_FACENo face detected in the second image
20011UNSUITABLE_VERTICAL_IMAGEVertical height requirement not met
20012UNSUITABLE_HORIZONTAL_IMAGEHorizontal width requirement not met
20013RESOLUTION_TOO_LARGE_ERRORResolution is too large
20014NOT_FOUNDImage not found
20015PICTURE_OVERRUN_ERRORImage exceeds the limit
20020DETECT_FACE_OUTOFIMAGEFacial features missing
20021DETECT_FACE_PITCHANGLE_BIGNot a frontal face; head nodding/pitch angle is too large
20022DETECT_FACE_YAWANGLE_BIGNot a frontal face; head shaking/rotation angle is too large
20023DETECT_FACE_LOWAREAFace occupies too small an area / pixel count is too low
21001LOAD_MODEL_ERRORFailed to load model
21002HAIR_MASK_LOSSHair mask missing
21003FACE_NUM_ERRORIncorrect number of faces
21004AR_PARSE_FAULTplist parsing error in AR
21005AR_EEEOR_COUNTAR face error
21006AR_FACE_OUTAR exceeds face range
21007JSON_ERRORJSON content error
21008BACKGROUND_IMAGE_LOSSBackground image missing
21009BODY_MASK_LOSSBody mask missing
21010FACE_ANGLE_ERRORFace angle error
21011SKIN_MASK_LOSSSkin mask missing
21012BODY_INFO_LOSSSkeleton points or outer contour points missing
21013RECT_OUT_IMAGEExceeds image range
30001GEN_ERRORGeneration error

General Error Codes and Messages

See API Error Codes for details.

Invocation Method

import requests
import json
import requests
from sign_sdk import sign

key = ""
secret = ""

def fetchResult(taskId):
    url = "https://openapi.meitu.com/api/v1/sdk/status?task_id="+taskId
    #key = "your api key"
    #secret = "your api secret"
    method = "GET"
    headers = {
        "Content-Type": "application/json",
        sign.HeaderHost: "openapi.meitu.com"
    }

    body = ""
    
    try:
        signer = sign.Signer(key, secret)

        signed_request = signer.sign(url,method,headers,body)
        session = requests.Session()
        response = session.send(signed_request,verify=False)
        if response.status_code==200:
            r=json.loads(response.content)
            if r["data"]["result"]["status"]=="10":
                # Task succeeded
                print(r["data"]["result"]["url"])
            elif r["data"]["result"]["status"]=="2" or r["data"]["result"]["status"]=="20": 
                # Task failed
                print(r["data"]["result"])
            else:
                # Task in progress
                fetchResult(taskId)
        else:
            print(response.text)

    except Exception as ex:
        print(ex)

url = "http://openapi.meitu.com/api/v1/sdk/sync/push"
method = "POST"
headers = {
    "Content-Type": "application/json",
    sign.HeaderHost: "openapi.meitu.com",
}
param = {
    "parameter": {
        "rsp_media_type": "url",
        "prompt_pos": "lipstick lying on satin fabric"
    }
}
imageUrl="https://obs-open-platform.obs.cn-north-4.myhuaweicloud.com/public/resources/img"
imagePositionMask="https://obs-open-platform.obs.cn-north-4.myhuaweicloud.com/public/resources/pos"
# 
body = json.dumps({
    # Note: params is of string type and requires json.dumps to convert the data structure once
    "params": json.dumps(param),
    "init_images": [
# Input original image
	{
        "url": imageUrl,
        "profiles": {
            "version": "v1"
        }
    },
# Input Mask image
{
        "url": imagePositionMask,
        "profiles": {
            "version": "v1"
        }
    }],
    "task": "/v1/InPainting/468520", # task in the invocation information
    "task_type": "formula" # task type in the invocation information
})

signer = sign.Signer(key, secret)
print(body)
signed_request = signer.sign(url, method, headers, body)
session = requests.Session()
response = session.send(signed_request,verify=False)

print(response.status_code)
print(response.text)
taskResult= json.loads(response.content)
taskId=taskResult["data"]["result"]["id"]

fetchResult(taskId,None)