Create Stunning Images with the fofr/kolors-with-ipadapter Cognitive Actions

22 Apr 2025
Create Stunning Images with the fofr/kolors-with-ipadapter Cognitive Actions

In today's digital landscape, the ability to generate high-quality images from textual descriptions is a game-changer for developers and artists alike. The fofr/kolors-with-ipadapter specification offers a powerful Cognitive Action that allows you to leverage advanced style and composition transfer techniques for text-to-image generation. By utilizing this action, developers can easily create visually appealing images that cater to various creative needs, whether for applications, marketing materials, or personal projects.

Prerequisites

Before you start integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • Basic familiarity with making API calls and handling JSON payloads.
  • A Python environment set up for executing the provided code snippets.

Authentication typically involves passing your API key in the headers of your HTTP requests, allowing secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Styled Image

The Generate Styled Image action utilizes the Kolors model for generating images based on text prompts. This action supports both Chinese and English characters, making it versatile for a global audience.

  • Category: Image Generation
  • Purpose: Generate high-quality images from text inputs, using an IPAdapter for style and composition.

Input

The input for this action is structured as a JSON object, requiring several fields to guide the image generation process. Here’s a breakdown of the required and optional fields based on the input_schema:

  • image (string, required): URI of the reference image for the IPAdapter.
  • prompt (string, optional): Text prompt to guide the image creation.
  • width (integer, optional): Width of the generated image in pixels (default: 1024).
  • height (integer, optional): Height of the generated image in pixels (default: 1024).
  • steps (integer, optional): Number of steps for inference (default: 25, range: 1-50).
  • sampler (string, optional): Algorithm for sampling (default: "dpmpp_2m_sde_gpu").
  • scheduler (string, optional): Type of scheduler (default: "karras").
  • outputFormat (string, optional): File format for the output image (default: "webp").
  • guidanceScale (number, optional): Influence of the prompt on image generation (default: 4, range: 0-20).
  • outputQuality (integer, optional): Quality of output images (default: 80, range: 0-100).
  • negativePrompt (string, optional): Concepts to exclude from the image.
  • numberOfImages (integer, optional): How many images to generate (default: 1, range: 1-10).
  • ipAdapterWeight (number, optional): Strength of IPAdapter influence (default: 1).
  • ipAdapterWeightType (string, optional): Method for IPAdapter adjustment (default: "style transfer precise").

Example Input:

{
  "image": "https://replicate.delivery/pbxt/LI5VAhU2v3jNTjuE76GMTzikT1XMiUoRSznZdXR0cAnK1XJS/ComfyUI_00362_.png",
  "steps": 25,
  "width": 1024,
  "height": 1024,
  "prompt": "an illustration of a cute dog jumping over a sleeping cat",
  "sampler": "dpmpp_2m_sde_gpu",
  "scheduler": "karras",
  "outputFormat": "webp",
  "guidanceScale": 4,
  "outputQuality": 80,
  "negativePrompt": "",
  "numberOfImages": 1,
  "ipAdapterWeight": 1,
  "ipAdapterWeightType": "style transfer precise"
}

Output

Upon successfully invoking the action, the response typically contains the generated image's URI. Here's what the output looks like:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/a99aebc9-34c7-45a2-9f90-14aa359a26c7/92e369bc-aa6b-4c2e-bd6a-2159794247ac.webp"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to call the Generate Styled Image 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 = "ce75c235-7c3c-42a8-ad79-71d43b66d463"  # Action ID for Generate Styled Image

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/LI5VAhU2v3jNTjuE76GMTzikT1XMiUoRSznZdXR0cAnK1XJS/ComfyUI_00362_.png",
    "steps": 25,
    "width": 1024,
    "height": 1024,
    "prompt": "an illustration of a cute dog jumping over a sleeping cat",
    "sampler": "dpmpp_2m_sde_gpu",
    "scheduler": "karras",
    "outputFormat": "webp",
    "guidanceScale": 4,
    "outputQuality": 80,
    "negativePrompt": "",
    "numberOfImages": 1,
    "ipAdapterWeight": 1,
    "ipAdapterWeightType": "style transfer precise"
}

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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key, and note how the action ID and input payload are structured correctly for the API call.

Conclusion

The Generate Styled Image action from the fofr/kolors-with-ipadapter specification offers an exciting opportunity for developers to create unique images from textual descriptions. By integrating this Cognitive Action into your applications, you can unlock new creative possibilities and enhance user engagement. Whether you're building a content creation tool, an artistic application, or simply experimenting with image generation, this action is a powerful asset in your development toolkit. Start integrating today and explore the endless creative potential!