Generate Stunning Images with the cocacha12/mark-flux Cognitive Actions

22 Apr 2025
Generate Stunning Images with the cocacha12/mark-flux Cognitive Actions

In the world of AI-driven creativity, the cocacha12/mark-flux API offers powerful Cognitive Actions to help developers generate images with precision and artistry. One of the standout features is the ability to create images through inpainting and image-to-image transformations. By leveraging pre-built actions, developers can seamlessly integrate advanced image generation capabilities into their applications without the need to train complex models from scratch.

Prerequisites

Before diving in, ensure you have access to the cocacha12/mark-flux API, which typically requires an API key for authentication. This key should be included in the headers of your requests to authenticate and authorize your application.

Cognitive Actions Overview

Generate Image Using Inpainting and Transformation

This action allows users to generate images based on specified prompts and parameters. It supports complex configurations, including inpainting and various transformation settings.

  • Category: Image Generation

Input

The input schema requires a prompt along with several optional parameters to refine the image generation process. Here’s a breakdown of the required and optional fields:

  • Required:
    • prompt: A string that describes what the image should depict. (Example: "TOK as a viking warrior ragnar lothbrok from vikings serie, close-up, professional photography.")
  • Optional:
    • mask: URI for an image mask in inpainting mode.
    • seed: Integer for random seed, facilitating reproducibility.
    • image: URI for an input image for transformations.
    • width & height: Dimensions of the output image (only if aspect_ratio is customized).
    • goFast: Boolean to enable faster predictions.
    • numOutputs: Integer to specify how many images to generate (1-4).
    • outputFormat: String to define the image format (e.g., webp, jpg, png).
    • Additional parameters like guidanceScale, modelWeights, extraLora, etc., to customize the generation further.

Here’s a practical example of the JSON payload needed to invoke this action:

{
  "prompt": "TOK as a viking warrior ragnar lothbrok from vikings serie, close-up, professional photography.",
  "loraScale": 1,
  "numOutputs": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "generationModel": "dev",
  "imageAspectRatio": "1:1",
  "numInferenceSteps": 28
}

Output

Upon successful execution, the action returns a URL pointing to the generated image. Here’s an example of an output:

[
  "https://assets.cognitiveactions.com/invocations/0035073a-0e01-4e3f-9368-d31bca13126e/8ef8f129-01d9-4e40-a7f6-c146621980e3.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Cognitive Actions execution endpoint for generating images:

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 = "aa533eac-8f32-421d-be30-9f002edebc2b" # Action ID for Generate Image Using Inpainting and Transformation

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "TOK as a viking warrior ragnar lothbrok from vikings serie, close-up, professional photography.",
    "loraScale": 1,
    "numOutputs": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "generationModel": "dev",
    "imageAspectRatio": "1:1",
    "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 code:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id is set for the "Generate Image Using Inpainting and Transformation" action.
  • The input JSON payload is constructed based on the action's requirements.

Conclusion

The cocacha12/mark-flux Cognitive Actions provide a powerful tool for developers looking to integrate advanced image generation capabilities into their applications. By utilizing the "Generate Image Using Inpainting and Transformation" action, you can create stunning visuals tailored to your specific needs. Whether you're building creative applications, enhancing media content, or exploring artistic expressions, these actions open up a world of possibilities.

Explore further, experiment with different parameters, and watch your ideas come to life!