Enhance Your Applications with the FOFR/SDXL-Demo: Image Inpainting Made Easy

23 Apr 2025
Enhance Your Applications with the FOFR/SDXL-Demo: Image Inpainting Made Easy

In the realm of artificial intelligence and image processing, the FOFR/SDXL-Demo offers powerful cognitive actions designed for developers seeking to enhance their applications with advanced image generation capabilities. Among these actions, the Generate Inpainted Image action stands out, allowing developers to create captivating visuals by intelligently inpainting images based on user-defined parameters. By leveraging these pre-built actions, you can save time and effort while ensuring high-quality outputs tailored to your needs.

Prerequisites

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

  • API Key: You will need an API key from the Cognitive Actions platform to authenticate your requests.
  • Environment Setup: Make sure your development environment is set up to make HTTP requests (e.g., using Python's requests library).

Authentication typically involves passing your API key in the request headers, allowing you to securely access the cognitive actions.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create an inpainted image from a source image by specifying masked regions for replacement. This action provides flexibility in terms of resolution, refinement, guidance, and more, making it an excellent tool for developers looking to create visually appealing content.

Input

The input schema for this action is structured as follows:

{
  "mask": "uri",
  "seed": 12345,
  "image": "uri",
  "width": 1024,
  "height": 1024,
  "prompt": "A photo of a TOK VR headset, a man is dancing",
  "refineStyle": "expert_ensemble_refiner",
  "guidanceScale": 7.5,
  "inversePrompt": "",
  "applyWatermark": true,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "refinementSteps": 10,
  "highNoiseFraction": 0.95,
  "inferenceStepCount": 50,
  "loraAdjustmentScale": 0.7,
  "schedulingAlgorithm": "K_EULER"
}

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A photo of a TOK VR headset, a man is dancing",
  "refineStyle": "expert_ensemble_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "highNoiseFraction": 0.95,
  "inferenceStepCount": 50,
  "loraAdjustmentScale": 0.7,
  "schedulingAlgorithm": "K_EULER"
}

Output

The output of the Generate Inpainted Image action will typically return a list of URLs pointing to the generated images. Here's an example of the output you can expect:

[
  "https://assets.cognitiveactions.com/invocations/c0404e68-bce3-4243-9411-36888949c33b/85ba6079-e346-464c-9b9e-eded9f17b32a.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet illustrating how to invoke the Generate Inpainted Image action using the Cognitive Actions endpoint:

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 = "7f5c13a4-f6f7-4144-84f5-815c7035061b" # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A photo of a TOK VR headset, a man is dancing",
    "refineStyle": "expert_ensemble_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "numberOfOutputs": 1,
    "promptIntensity": 0.8,
    "highNoiseFraction": 0.95,
    "inferenceStepCount": 50,
    "loraAdjustmentScale": 0.7,
    "schedulingAlgorithm": "K_EULER"
}

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, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for the Generate Inpainted Image is specified, and the input payload is constructed based on the schema provided. The request is sent to the hypothetical endpoint, and the response is handled accordingly.

Conclusion

The FOFR/SDXL-Demo Cognitive Actions, particularly the Generate Inpainted Image action, empower developers to create stunning visual content with ease. By leveraging the capabilities of this action, you can enhance your applications and provide users with engaging, high-quality images. Explore the various parameters available and consider how you can integrate this functionality into your projects to unlock new creative possibilities.