Create Stunning Art with charlesdoiron/joy Cognitive Actions

24 Apr 2025
Create Stunning Art with charlesdoiron/joy Cognitive Actions

In the world of creative digital content, the ability to generate unique artwork can provide a competitive edge to applications. The charlesdoiron/joy Cognitive Actions offer developers the power to create visually striking images styled in the whimsical manner of Julie Cesare. By leveraging these pre-built actions, developers can seamlessly integrate advanced image generation capabilities into their applications, allowing for customization and artistic expression.

Prerequisites

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

  • Access to the Cognitive Actions platform and an API key for authentication.
  • Familiarity with making HTTP requests and handling JSON data.

To authenticate your requests, you typically need to pass your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Instagram-Style Artwork

Description: This action allows you to create images that mimic the artistic style of Julie Cesare with options for customization such as masks, seeds, sizes, and various refining techniques.

Category: Image Generation

Input

The input for this action requires a JSON object that can include the following fields:

  • mask (string, optional): A URI pointing to an input mask.
  • seed (integer, optional): An integer for setting the random seed.
  • image (string, optional): A URI to an input image.
  • width (integer, default 1024): Desired width of the output image.
  • height (integer, default 1024): Desired height of the output image.
  • prompt (string, default "An astronaut riding a rainbow unicorn"): Textual prompt guiding image generation.
  • refine (string, default "no_refiner"): Refiner style to apply (options include no_refiner, expert_ensemble_refiner, base_image_refiner).
  • weights (string, optional): LoRA weights to utilize.
  • loraScale (number, default 0.6): Scale for LoRA additive effect.
  • scheduler (string, default "K_EULER"): Algorithm for scheduling during image generation.
  • numOutputs (integer, default 1): Number of images to output (1 to 4).
  • refineSteps (integer, optional): Number of refinement steps for 'base_image_refiner'.
  • guidanceScale (number, default 7.5): Scale of classifier-free guidance.
  • highNoiseFrac (number, default 0.8): Noise fraction for the 'expert_ensemble_refiner'.
  • applyWatermark (boolean, default true): Whether to apply a watermark on generated images.
  • negativePrompt (string, optional): A negative prompt to de-emphasize certain aspects.
  • promptStrength (number, default 0.8): Strength of the prompt.
  • numInferenceSteps (integer, default 50): Number of denoising steps.
  • disableSafetyChecker (boolean, default false): If the safety checker is disabled.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "In the style of JOY, a little house on an island on a lake",
  "refine": "no_refiner",
  "loraScale": 0.72,
  "scheduler": "K_EULER",
  "numOutputs": 1,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.55,
  "applyWatermark": true,
  "promptStrength": 0.43,
  "numInferenceSteps": 50
}

Output

Upon successful execution, the action typically returns a URL to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/969d8424-ab4e-4195-a637-bd8d6f304e2b/f43a5dbd-f770-4d88-8ff8-8696656915df.png"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Instagram-Style Artwork action using Python:

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 = "c9575021-3fb7-49ee-8ed8-6a875e52fd47"  # Action ID for Generate Instagram-Style Artwork

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "In the style of JOY, a little house on an island on a lake",
    "refine": "no_refiner",
    "loraScale": 0.72,
    "scheduler": "K_EULER",
    "numOutputs": 1,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.55,
    "applyWatermark": True,
    "promptStrength": 0.43,
    "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 this code snippet, replace the COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your actual API key and endpoint. The payload variable is structured according to the action's input schema.

Conclusion

The charlesdoiron/joy Cognitive Actions empower developers to easily integrate sophisticated image generation capabilities into their applications. With the ability to customize artistic styles, refine outputs, and control various parameters, the potential use cases are vast—from creative marketing materials to personalized user experiences. Start experimenting with these actions today, and bring delightful artistic creations to your projects!