Create Stunning Custom Images with the FlashFace Cognitive Actions

24 Apr 2025
Create Stunning Custom Images with the FlashFace Cognitive Actions

Integrating advanced image processing capabilities into your applications is now easier than ever with the FlashFace API. This powerful platform enables developers to personalize high-fidelity human images using reference faces and language prompts. By leveraging these pre-built actions, you can create customized images while maintaining individual identities, offering a unique experience to your users.

Prerequisites

Before diving into the FlashFace Cognitive Actions, make sure you have the following:

  • An API key for the FlashFace platform to authenticate your requests.
  • Familiarity with making HTTP requests in your programming environment, particularly for sending JSON payloads in your API calls.

In conceptual terms, you will typically include your API key in the headers of your requests as follows:

headers = {
    "Authorization": f"Bearer {YOUR_API_KEY}",
    "Content-Type": "application/json"
}

Cognitive Actions Overview

Personalize Human Image with FlashFace

Description: This action utilizes the FlashFace model for high-fidelity human image personalization. It allows users to create custom images by leveraging reference faces and language prompts while preserving individual identity.

Category: image-processing

Input

The input for this action is structured as follows:

FieldTypeRequiredDescription
positivePromptTextstringYesA prompt encouraging specific desired elements in the generated image.
referenceFaceImage1stringYesURI pointing to the first reference face image.
seedintegerNoRandom seed for image generation. Leave blank for randomization.
stepsintegerNoNumber of steps to perform (default is 35). Increasing this may improve quality at the cost of processing time.
faceBoundingBoxstringNoDefines the bounding box for the face. Default value implies detection is automated.
numberOfSamplesintegerNoNumber of images to generate (default is 1).
outputImageFormatstringNoFile format for the output images (options: webp, jpg, png; default is webp).
negativePromptTextstringNoPrompt to discourage undesired elements in the generated image (default is "nsfw").
outputImageQualityintegerNoQuality of the output images, from 0 to 100 (default is 80).
textControlStrengthnumberNoControls the influence of the text prompt on the image.
faceGuidanceStrengthnumberNoDetermines how strongly the model follows the reference images.
defaultNegativePromptstringNoDefault string to reduce unwanted traits in generated images.
defaultPositionPromptstringNoDefault string to enhance quality and detail in generated images.
lambdaFeatureStrengthnumberNoIntensity for using the reference face features for guidance.
stepToActivateFaceGuidanceintegerNoThe step index at which to begin using reference guidance for generation.

Example Input:

{
  "seed": 0,
  "steps": 50,
  "faceBoundingBox": "[0., 0., 0., 0.]",
  "numberOfSamples": 2,
  "outputImageFormat": "webp",
  "negativePromptText": "nsfw",
  "outputImageQuality": 80,
  "positivePromptText": "A handsome young man with long brown hair is sitting in the desert",
  "referenceFaceImage1": "https://replicate.delivery/pbxt/KnE00y2FMOW0170eWcdyDUe09FZLCKiJrDwYYCUp42yWdni0/avatar.png",
  "textControlStrength": 7.5,
  "faceGuidanceStrength": 2.5,
  "defaultNegativePrompt": "blurry, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face",
  "defaultPositionPrompt": "best quality, masterpiece,ultra-detailed, UHD 4K, photographic",
  "lambdaFeatureStrength": 0.9,
  "stepToActivateFaceGuidance": 700
}

Output

The action typically returns a list of URLs pointing to the generated images. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/48adc18b-cb60-44fd-9d70-326c18c4fcff/b19c7541-fd8c-4dc7-a6b1-ce708a4ac219.webp",
  "https://assets.cognitiveactions.com/invocations/48adc18b-cb60-44fd-9d70-326c18c4fcff/f1912fa7-c62b-4db1-a880-3c1adde51f0b.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call the Personalize Human Image with FlashFace action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "56b7c14c-c0d8-4961-a2fb-deed7e7a88e2"  # Action ID for Personalize Human Image with FlashFace

# Construct the input payload based on the action's requirements
payload = {
    "seed": 0,
    "steps": 50,
    "faceBoundingBox": "[0., 0., 0., 0.]",
    "numberOfSamples": 2,
    "outputImageFormat": "webp",
    "negativePromptText": "nsfw",
    "outputImageQuality": 80,
    "positivePromptText": "A handsome young man with long brown hair is sitting in the desert",
    "referenceFaceImage1": "https://replicate.delivery/pbxt/KnE00y2FMOW0170eWcdyDUe09FZLCKiJrDwYYCUp42yWdni0/avatar.png",
    "textControlStrength": 7.5,
    "faceGuidanceStrength": 2.5,
    "defaultNegativePrompt": "blurry, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face",
    "defaultPositionPrompt": "best quality, masterpiece,ultra-detailed, UHD 4K, photographic",
    "lambdaFeatureStrength": 0.9,
    "stepToActivateFaceGuidance": 700
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload contains the required and optional fields for the action. The example demonstrates how to structure the input and handle responses effectively.

Conclusion

The FlashFace Cognitive Action offers a powerful way to create personalized images, enhancing user experience in your applications. With the ability to customize images using various prompts and reference faces, the possibilities are vast. Explore these actions further to see how they can fit into your projects and consider integrating them for innovative image processing solutions!