Enhance Your Applications with the Flux for Michael Cognitive Actions

24 Apr 2025
Enhance Your Applications with the Flux for Michael Cognitive Actions

In the realm of image generation and manipulation, the Flux for Michael Cognitive Actions enable developers to seamlessly integrate advanced image processing capabilities into their applications. With these pre-built actions, you can generate inpainted images using high-quality models, ensuring speed and efficiency. This blog post will guide you through the powerful features of the Generate Inpainted Image action and provide you with practical examples to get started.

Prerequisites

Before diving into the integration of the Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform. This key will be used in the request headers for authentication.
  • Familiarity with JSON format, as you'll be constructing input payloads in this format.

For authentication, you typically pass your API key in the headers of your HTTP requests, allowing you to securely access the services provided by the Cognitive Actions platform.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create new images by filling in missing parts of an existing image or generating entirely new visuals based on a textual prompt. This powerful action supports multiple configurations, including custom aspect ratios and output formats, and utilizes optimized models for enhanced image quality and speed.

Input

The input schema for this action requires the following fields:

  • prompt (required): A textual description guiding the image generation.
  • mask (optional): URI of the image mask for inpainting mode.
  • seed (optional): Integer seed for reproducibility.
  • image (optional): URI of the input image for inpainting.
  • width (optional): Custom width in pixels (if aspect_ratio is custom).
  • height (optional): Custom height in pixels (if aspect_ratio is custom).
  • aspectRatio (optional): Pre-defined or custom aspect ratio (default: 1:1).
  • outputCount (optional): Number of images to generate (min: 1, max: 4).
  • outputFormat (optional): Format of the output images (default: webp).
  • guidanceScale (optional): Scale for guidance during generation (default: 3).
  • outputQuality (optional): JPEG quality setting (default: 80).
  • extraLoraScale (optional): Strength of additional LoRA application.
  • inferenceModel (optional): Model selection for inference (default: dev).
  • promptStrength (optional): Influence strength of the prompt (default: 0.8).
  • numInferenceSteps (optional): Steps for denoising (default: 28).
  • safetyCheckDisabled (optional): Toggle for disabling safety checker.

Example Input:

{
  "prompt": "headshot of TOKmachine, he is wearing Meta Ray-Ban smart glasses, he is dressed in a banana republic blazer, his hair is thick, he is walking down a busy street in manhattan",
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "mainModelScale": 1,
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output

The action typically returns a URL pointing to the generated image. If successful, you will receive an array containing the image URLs.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/98110b66-3bcf-4497-87a7-9e76a70b7b8d/203dbf74-1dc6-4247-be8c-a58f4641deea.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Inpainted Image action using Python. This snippet provides a structure to execute the action with the required input.

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 = "35013850-8a65-4ea5-8437-8a2e3fa40013" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "headshot of TOKmachine, he is wearing Meta Ray-Ban smart glasses, he is dressed in a banana republic blazer, his hair is thick, he is walking down a busy street in manhattan",
    "aspectRatio": "1:1",
    "outputCount": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "mainModelScale": 1,
    "promptStrength": 0.8,
    "numInferenceSteps": 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 would replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is constructed according to the required input fields, and the request is sent to the hypothetical endpoint for action execution.

Conclusion

The Generate Inpainted Image action from the Flux for Michael Cognitive Actions offers immense potential for developers looking to enhance their applications with advanced image generation capabilities. By leveraging this action, you can generate stunning visuals tailored to your specifications. Explore different configurations to see how they affect the output, and consider integrating this functionality into your projects for a richer user experience. Happy coding!