Enhance Your Applications with Image Generation Using fofr/flux-antiquities Cognitive Actions

24 Apr 2025
Enhance Your Applications with Image Generation Using fofr/flux-antiquities Cognitive Actions

In the realm of AI-driven creativity, the fofr/flux-antiquities API offers powerful Cognitive Actions that leverage advanced image generation techniques. These actions enable developers to create unique and customizable images through inpainting and various configurable parameters. With pre-built capabilities, integrating these actions into your applications can significantly enhance user experiences and streamline creative workflows.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and RESTful APIs.
  • A programming environment set up to make HTTP requests (Python is used in the examples).

For authentication, you typically pass your API key in the request headers, allowing secure access to the Cognitive Actions services.

Cognitive Actions Overview

Generate Images with Inpainting

Purpose

The "Generate Images with Inpainting" action allows developers to create images by utilizing inpainting techniques. This action provides customization options through various parameters, including model selection, image masks, and output specifications. Developers can choose between detailed outputs and faster predictions based on their needs.

Input

The input schema for this action requires a prompt, with several optional parameters to enhance the image generation process. Below is the schema breakdown:

  • Required Field:
    • prompt: A description that guides the generation of the image (e.g., "a photo of an antiquities sculpture").
  • Optional Fields:
    • mask: (string) URI for an image mask used in inpainting mode.
    • seed: (integer) Random seed for consistent outputs.
    • image: (string) URI for an input image (used in image-to-image or inpainting mode).
    • width: (integer) Width of the generated image (only for custom aspect ratios).
    • height: (integer) Height of the generated image (only for custom aspect ratios).
    • goFast: (boolean) Enables faster image generation.
    • imageFormat: (string) Format of the output image (options: webp, jpg, png).
    • outputCount: (integer) Number of images to generate (1 to 4).
    • imageQuality: (integer) Quality of the output image (0 to 100).
    • modelType: (string) Chooses between 'dev' and 'schnell' models.
    • inferenceStepsCount: (integer) Number of denoising steps for enhanced detail.
    • Additional parameters include Lora scaling and aspect ratio settings.

Example Input

Here’s an example of a JSON payload that might be used to invoke this action:

{
  "goFast": false,
  "prompt": "a photo of an antiquities sculpture",
  "loraScale": 1,
  "modelType": "dev",
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 80,
  "maxResolution": "1",
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "guidanceStrength": 3,
  "imageAspectRatio": "1:1",
  "inferenceStepsCount": 28
}

Output

The action typically returns an array of generated image URLs. Here’s an example of a response:

[
  "https://assets.cognitiveactions.com/invocations/e340f796-6d5b-43c7-9c3f-e8fabb5e9898/c954c071-d99f-452f-ac67-f5745cd022dc.webp"
]

Conceptual Usage Example (Python)

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

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 = "3efa6052-feeb-4025-a93c-ea25349dfa39"  # Action ID for Generate Images with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "a photo of an antiquities sculpture",
    "loraScale": 1,
    "modelType": "dev",
    "imageFormat": "webp",
    "outputCount": 1,
    "imageQuality": 80,
    "maxResolution": "1",
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "guidanceStrength": 3,
    "imageAspectRatio": "1:1",
    "inferenceStepsCount": 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}")

This Python snippet illustrates how to structure the API request for generating images with inpainting. You need to replace the API key and endpoint with your actual values.

Conclusion

The fofr/flux-antiquities Cognitive Actions provide a robust framework for developers to integrate advanced image generation capabilities into their applications. By leveraging the "Generate Images with Inpainting" action, you can create visually stunning images tailored to your specific requirements. Consider exploring additional use cases, such as enhancing user-generated content or automating creative processes in your applications. Happy coding!