Create Stunning Images with the Charlottealafraise Cognitive Actions

21 Apr 2025
Create Stunning Images with the Charlottealafraise Cognitive Actions

In the world of digital content creation, the ability to generate high-quality images programmatically can greatly enhance your applications. The Charlottealafraise Cognitive Actions provide a powerful toolset for image generation, allowing developers to create stunning visuals tailored to specific prompts and parameters. This blog post explores how to leverage the "Generate Image with Mask and Inpainting" action to produce unique images efficiently.

Prerequisites

To start using the Charlottealafraise Cognitive Actions, you will need the following:

  • API Key: Register on the Cognitive Actions platform to obtain your API key.
  • Basic Knowledge of JSON: Understanding JSON structures will help you format your requests correctly.
  • Python Environment: Make sure you have a Python environment set up with the requests library installed for making HTTP requests.

Authentication is typically done by passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image with Mask and Inpainting

The Generate Image with Mask and Inpainting action creates an image based on a given prompt, allowing for extensive customization through various parameters such as image masks, aspect ratios, and output qualities. This action is part of the image-generation category and is particularly useful for applications that require dynamic image creation based on user input or predefined templates.

Input

The input for this action requires a JSON object with the following properties:

  • prompt (required): A text prompt for generating the image. Example: "professionnal picture of juliewitg blond hair for a cv with black dress".
  • mask (optional): URI of the image mask for inpainting mode.
  • seed (optional): An integer seed for reproducible results.
  • image (optional): URI of the input image for image-to-image or inpainting mode.
  • width (optional): The width of the generated image.
  • height (optional): The height of the generated image.
  • loraWeights (optional): Load additional model weights.
  • mainLoraScale (optional): Application strength of the main LoRA.
  • inferenceModel (optional): Choose between "dev" or "schnell" for inference.
  • inferenceSteps (optional): Number of denoising steps during inference.
  • accelerateModel (optional): Enable faster predictions.
  • numberOfOutputs (optional): Specifies how many images to generate.
  • promptIntensity (optional): Defines the strength of the prompt in img2img mode.
  • imageAspectRatio (optional): Specifies the aspect ratio.
  • imageOutputFormat (optional): Defines the output image format.
  • imageOutputQuality (optional): Sets the quality of the output images.
  • additionalLoraScale (optional): Defines the strength for additional LoRA.
  • additionalLoraWeights (optional): Use additional LoRA weights.
  • approximateMegapixels (optional): Approximate pixel count for the output.
  • safetyCheckerDisabled (optional): Disable safety checks on generated images.
  • diffusionGuidanceScale (optional): Affects diffusion guidance.

Example Input:

{
  "prompt": "professionnal picture of juliewitg blond hair for a cv with black dress",
  "mainLoraScale": 1,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "accelerateModel": false,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "approximateMegapixels": "1",
  "diffusionGuidanceScale": 3
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/efd0e1d9-956d-4971-8023-ffd3d44e48ee/cca0336c-1a98-4bfd-93fe-779d869899ea.webp"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Mask and Inpainting 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 = "27e13589-f436-44a7-84f8-d61c7b24a15c"  # Action ID for Generate Image with Mask and Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "professionnal picture of juliewitg blond hair for a cv with black dress",
    "mainLoraScale": 1,
    "inferenceModel": "dev",
    "inferenceSteps": 28,
    "accelerateModel": False,
    "numberOfOutputs": 1,
    "promptIntensity": 0.8,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "additionalLoraScale": 1,
    "approximateMegapixels": "1",
    "diffusionGuidanceScale": 3
}

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, you will replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and ensure the endpoint URL is correct. The JSON payload is structured according to the action's requirements, and the response is processed to display the generated image URLs.

Conclusion

The Charlottealafraise Cognitive Actions, specifically the Generate Image with Mask and Inpainting action, empower developers to create dynamic and tailored images for a variety of applications. By understanding how to structure inputs and handle outputs, you can easily integrate these capabilities into your projects. Explore the possibilities for enhancing user engagement and creativity in your applications with these powerful tools!