Enhance Your Images with the farbodmehr/fcm4 Cognitive Actions

23 Apr 2025
Enhance Your Images with the farbodmehr/fcm4 Cognitive Actions

In the realm of image manipulation and generation, the farbodmehr/fcm4 API offers powerful Cognitive Actions that can transform the way developers enhance and create images. Among these actions, the ability to generate images with advanced inpainting techniques stands out. This action not only promises to create visually stunning results but also provides flexibility through customizable parameters. In this article, we'll explore how to leverage this capability and integrate it into your applications seamlessly.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which will allow you to authenticate your requests.
  • Familiarity with making HTTP requests and handling JSON data.
  • Basic knowledge of Python for the conceptual usage example provided in this article.

Authentication typically involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create an enhanced image using inpainting techniques. You can specify various parameters such as image dimensions, prompt strength, and refinements, ensuring both quality and flexibility. It supports multiple output images and scheduling strategies, making it a versatile tool for developers.

Input

The action requires the following fields in the input schema:

  • mask (string, optional): URI of the input mask for inpaint mode. Black areas will be preserved, while white areas will be inpainted.
  • seed (integer, optional): Seed for random number generation. Leave empty to generate a random seed.
  • image (string, required): URI of the input image for img2img or inpaint mode.
  • width (integer, optional): Width of the output image (default is 1024).
  • height (integer, optional): Height of the output image (default is 1024).
  • prompt (string, optional): Text prompt for generating the image (default is "An astronaut riding a rainbow unicorn").
  • loraScale (number, optional): Scale factor for LoRA models (default is 0.6).
  • scheduler (string, optional): Method used for image generation steps (default is "K_EULER").
  • refineSteps (integer, optional): Number of refinement steps for base_image_refiner.
  • refineStyle (string, optional): Style of refinement to use (default is "no_refiner").
  • customWeights (string, optional): Custom LoRA weights to use for the model.
  • guidanceScale (number, optional): Scale for classifier-free guidance (default is 7.5).
  • applyWatermark (boolean, optional): Apply a watermark to generated images (default is true).
  • negativePrompt (string, optional): Text prompt for features to avoid in the image (default is empty).
  • promptStrength (number, optional): Controls strength of the image transformation (default is 0.8).
  • numberOfOutputs (integer, optional): Number of images to generate (default is 1).
  • highNoiseFraction (number, optional): Fraction of noise for expert_ensemble_refiner (default is 0.8).
  • numInferenceSteps (integer, optional): Total number of denoising steps (default is 50).
  • disableSafetyChecker (boolean, optional): Option to disable the safety checker for generated images (default is false).

Here’s an example input payload for the action:

{
  "width": 1024,
  "height": 1024,
  "prompt": "image of TOK Soccer player in style of TOK",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numInferenceSteps": 50
}

Output

Upon successful execution, this action returns a list of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/d0e270c2-2708-4f14-83ab-0b5c97b6b6d9/e5afe946-6de9-4941-97c0-f09b43258f4e.png"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how to invoke the Generate Image with Inpainting action using a hypothetical 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 = "29b79a95-7ed3-487e-98ac-e43584450fba" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "image of TOK Soccer player in style of TOK",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "numInferenceSteps": 50
}

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 the above code, we replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and specify the action ID for the image generation. The input payload is constructed based on the action's schema, ensuring all required parameters are included.

Conclusion

The Generate Image with Inpainting action from the farbodmehr/fcm4 API is a robust tool for developers looking to enhance their applications with advanced image generation capabilities. By utilizing customizable parameters and flexible output options, you can easily create stunning visuals tailored to your project’s needs.

Explore further by experimenting with different prompts, styles, and settings to unlock the full potential of this Cognitive Action in your applications!