Transform Your Portraits with zsxkib/infinite-you Cognitive Actions

23 Apr 2025
Transform Your Portraits with zsxkib/infinite-you Cognitive Actions

The zsxkib/infinite-you spec offers a powerful tool for developers looking to integrate advanced image transformation capabilities into their applications. With the Cognitive Actions provided, you can transform portrait photos into various styles while preserving facial identity. This is achieved through the InfiniteYou model, which excels in high text-image alignment and seamless integration. Let's dive into how you can leverage these actions to enhance your applications.

Prerequisites

Before you begin, ensure you have access to the Cognitive Actions platform and obtain your API key. Authentication generally involves passing this API key in the request headers. Make sure to keep your key secure and do not expose it in client-side code.

Cognitive Actions Overview

Transform Portraits While Preserving Identity

The Transform Portraits While Preserving Identity action enables you to transform portrait images into different styles while maintaining the facial identity of the person in the image. This action is particularly useful for applications in social media, gaming, and creative content generation.

Input

This action requires a specific input schema which includes several fields:

  • identityImage (required): The URL to the portrait image you want to transform.
  • seed (optional): A random seed for reproducibility. Use 'None' for a random seed.
  • width (optional): Width of the output image (default: 864, range: 256-1280).
  • height (optional): Height of the output image (default: 1152, range: 256-1280).
  • prompt (optional): A detailed description of the desired appearance for the generated image (default: "Portrait, 4K, high quality, cinematic").
  • controlImage (optional): A secondary image to influence pose or position.
  • modelVersion (optional): Select between 'aes_stage2' (default) for enhanced aesthetics or 'sim_stage1' for higher identity similarity.
  • outputFormat (optional): Choose output format (default: webp; options: PNG, JPG).
  • enableRealism (optional): Enables realism enhancement (default: false).
  • guidanceScale (optional): Determines adherence to the prompt (default: 3.5, range: 0-10).
  • numberOfSteps (optional): The number of diffusion steps (default: 30, range: 1-100).
  • outputQuality (optional): Quality for JPG and WEBP formats (default: 80, range: 1-100).
  • enableAntiBlur (optional): Applies anti-blur enhancement (default: false).
  • infusenetGuidanceStart, infusenetGuidanceEnd, infusenetConditioningScale (optional): Advanced parameters for fine-tuning identity guidance.

Example Input:

{
  "width": 864,
  "height": 1152,
  "prompt": "a woman with perfect eyes",
  "modelVersion": "sim_stage1",
  "enableRealism": true,
  "guidanceScale": 3.5,
  "identityImage": "https://replicate.delivery/pbxt/L0gy7uyLE5UP0uz12cndDdSOIgw5R3rV5N6G2pbt7kEK9dCr/0_3.webp",
  "numberOfSteps": 30,
  "enableAntiBlur": true,
  "infusenetGuidanceEnd": 1,
  "infusenetGuidanceStart": 0,
  "infusenetConditioningScale": 1
}

Output

Upon successful execution, the action typically returns a URL linking to the transformed image, allowing seamless integration into your application.

Example Output:

https://assets.cognitiveactions.com/invocations/4d105888-e1de-452f-963f-c93da05a3f23/a2bc3ae9-ccbd-46e4-879c-ca853d787c76.webp

Conceptual Usage Example (Python)

Here's how you might call this 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 = "328c7277-b9c0-4c22-a6f9-940cae380da4"  # Action ID for Transform Portraits While Preserving Identity

# Construct the input payload based on the action's requirements
payload = {
    "width": 864,
    "height": 1152,
    "prompt": "a woman with perfect eyes",
    "modelVersion": "sim_stage1",
    "enableRealism": True,
    "guidanceScale": 3.5,
    "identityImage": "https://replicate.delivery/pbxt/L0gy7uyLE5UP0uz12cndDdSOIgw5R3rV5N6G2pbt7kEK9dCr/0_3.webp",
    "numberOfSteps": 30,
    "enableAntiBlur": True,
    "infusenetGuidanceEnd": 1,
    "infusenetGuidanceStart": 0,
    "infusenetConditioningScale": 1
}

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, we replace the action ID and input payload with the appropriate values for the Transform Portraits While Preserving Identity action. The endpoint URL and request structure are illustrative, so ensure to adapt them according to the actual API documentation.

Conclusion

With the Transform Portraits While Preserving Identity action from the zsxkib/infinite-you spec, developers can easily integrate advanced image transformation capabilities into their applications, enhancing user experience and creativity. Explore further use cases by combining this action with other functionalities to create a more dynamic application!