Transform Images with the Sylvester Flux Selfie Cognitive Actions

22 Apr 2025
Transform Images with the Sylvester Flux Selfie Cognitive Actions

In today's digital landscape, enhancing images through intelligent transformations can significantly elevate user experiences. The sylvesteraswin/sylvester-flux-selfie API provides a powerful toolset known as Cognitive Actions that allows developers to perform advanced image processing tasks. Among these actions, you can achieve detailed image inpainting and transformation, ensuring high-quality outputs tailored to various applications.

Prerequisites

Before diving into the functionality of these Cognitive Actions, make sure you have:

  • An API key for the Cognitive Actions platform.
  • Basic familiarity with JSON structures and HTTP requests.
  • Conceptual understanding of how to pass authentication tokens in headers (typically as a Bearer token).

Cognitive Actions Overview

Perform Image Inpainting and Transformation

This action utilizes either the 'dev' or 'schnell' model to perform detailed image-to-image transformations and inpainting. You can customize the operation using various parameters, ensuring high-quality images suitable for different settings.

Input

The input schema for this action requires several fields, with prompt being mandatory. Here’s a breakdown:

  • prompt: string (required)
    The textual description for the image generation.
  • mask: string (optional)
    A URI for the image mask used in inpainting mode.
  • image: string (optional)
    A URI for the input image for transformations.
  • model: string (optional, default: "dev")
    Choose between "dev" (28 steps) or "schnell" (4 steps) for inference.
  • width: integer (optional)
    Desired width of the output image (256-1440).
  • height: integer (optional)
    Desired height of the output image (256-1440).
  • guidanceScale: number (optional, default: 3)
    Scale for guiding the diffusion process (0-10).
  • numberOfOutputs: integer (optional, default: 1)
    Number of output images to generate (1-4).

Here’s an example input payload:

{
  "model": "dev",
  "prompt": "A highly detailed studio portrait of SYL_07_08, a 38-year-old male, wearing sleek prescription glasses and giving a playful, naughty smile. The setting is a professional photo studio with a completely black background and dramatic, professional lighting that highlights his facial features clearly. The shot includes SYL_07_08 from head to hip, dressed in a modern suit. His posture is relaxed, and the lighting casts soft shadows, accentuating the mischievous expression on his face while maintaining an elegant and professional atmosphere.",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "guidanceScale": 3.5,
  "numberOfOutputs": 1,
  "outputImageFormat": "webp",
  "outputImageQuality": 90,
  "additionalLoraScale": 1,
  "inputPromptStrength": 0.8,
  "numberOfInferenceSteps": 28
}

Output

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

[
  "https://assets.cognitiveactions.com/invocations/1b9eb4a2-0354-45db-97c6-6582e58e6074/17c261be-dc29-417b-bc72-6f82a5bdf872.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 = "218af7d5-dafe-4e11-81b2-5db80a4e9e3f"  # Action ID for Perform Image Inpainting and Transformation

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "A highly detailed studio portrait of SYL_07_08, a 38-year-old male, wearing sleek prescription glasses and giving a playful, naughty smile. The setting is a professional photo studio with a completely black background and dramatic, professional lighting that highlights his facial features clearly. The shot includes SYL_07_08 from head to hip, dressed in a modern suit. His posture is relaxed, and the lighting casts soft shadows, accentuating the mischievous expression on his face while maintaining an elegant and professional atmosphere.",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "guidanceScale": 3.5,
    "numberOfOutputs": 1,
    "outputImageFormat": "webp",
    "outputImageQuality": 90,
    "additionalLoraScale": 1,
    "inputPromptStrength": 0.8,
    "numberOfInferenceSteps": 28
}

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 snippet, you replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and utilize the specified action ID. The input payload is structured to meet the action's requirements.

Conclusion

The Perform Image Inpainting and Transformation action within the sylvesteraswin/sylvester-flux-selfie Cognitive Actions offers a remarkable opportunity for developers to create stunning images through intelligent processing. By leveraging customizable parameters and models, you can enhance the visual quality of your applications.

Explore these capabilities to automate and innovate in your image-processing workflows!