Enhance Your App with Image Generation Using alexdiazus/instaxmini12 Cognitive Actions

24 Apr 2025
Enhance Your App with Image Generation Using alexdiazus/instaxmini12 Cognitive Actions

Integrating advanced image generation capabilities into your applications can transform user experiences, allowing for creative outputs tailored to specific needs. The alexdiazus/instaxmini12 Cognitive Actions offer a powerful toolset to generate images through a sophisticated inpainting method, enabling customization across various parameters. In this blog post, we’ll explore how to effectively use these Cognitive Actions to create stunning images by leveraging the provided actions and their features.

Prerequisites

Before diving into the integration process, ensure you have the following prerequisites:

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests and handling JSON data.
  • Basic knowledge of Python for the usage examples.

Authentication typically involves passing your API key in the headers of your requests to authorize access to the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Inpainting

Description: This action generates an image using an advanced inpainting method, allowing for customization of dimensions, prompt intensity, and output format. You can choose between 'dev' for detailed inference or 'schnell' for faster results with fewer steps.

Category: image-generation

Input

The input schema for this action consists of several fields, with prompt being required. Below is a summary of the key input fields:

  • prompt (string, required): Text prompt guiding the image generation.
  • mask (string, optional): URI for the image mask used in inpainting mode.
  • seed (integer, optional): Random seed for reproducibility.
  • image (string, optional): URI for the input image in image-to-image mode.
  • width (integer, optional): Width of the generated image (when aspect_ratio is 'custom').
  • height (integer, optional): Height of the generated image (when aspect_ratio is 'custom').
  • goFast (boolean, optional): Enables faster predictions with optimized speed.
  • numberOfOutputs (integer, optional): Number of output images to generate (1 to 4).
  • outputImageFormat (string, optional): Format for the output images (webp, jpg, png).

Example Input:

{
  "prompt": "TOK_intax Fashion photo series featuring a young Latina model with Colombian features and fair skin, posing with an Instax Mini camera case. The model has dark hair, brown eyes, and delicate facial features typical of the Colombian Andean region. She wears modern, trendy clothing, changing outfits in each scene. The Instax Mini case is colorful and clearly visible in her hands or hanging from her shoulder",
  "mainLoraScale": 1,
  "selectedModel": "dev",
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "imageAspectRatio": "9:16",
  "outputImageFormat": "webp",
  "imageGuidanceScale": 3.5,
  "imageOutputQuality": 90,
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28
}

Output

The action typically returns an array of URIs pointing to the generated images. Below is an example of the output you can expect:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/99b97572-34d3-4e74-bba9-4f91577c1d8a/31215ac2-7281-47d5-b633-9f1fdf6bfe93.webp",
  "https://assets.cognitiveactions.com/invocations/99b97572-34d3-4e74-bba9-4f91577c1d8a/c7391d63-6f04-4046-97b6-ba7f8051f17b.webp",
  "https://assets.cognitiveactions.com/invocations/99b97572-34d3-4e74-bba9-4f91577c1d8a/ce3f4f8b-26e5-492c-877b-aaa708fbe20d.webp",
  "https://assets.cognitiveactions.com/invocations/99b97572-34d3-4e74-bba9-4f91577c1d8a/074d2454-395b-462f-9d15-71c5f02bb427.webp"
]

Conceptual Usage Example (Python)

Here’s how you can call the Generate Image with Inpainting action using a conceptual Python code snippet:

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 = "68e894f5-f85d-4229-ab05-f2bbb5530a8f"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "TOK_intax Fashion photo series featuring a young Latina model with Colombian features and fair skin, posing with an Instax Mini camera case. The model has dark hair, brown eyes, and delicate facial features typical of the Colombian Andean region. She wears modern, trendy clothing, changing outfits in each scene. The Instax Mini case is colorful and clearly visible in her hands or hanging from her shoulder",
    "mainLoraScale": 1,
    "selectedModel": "dev",
    "promptStrength": 0.8,
    "numberOfOutputs": 4,
    "imageAspectRatio": "9:16",
    "outputImageFormat": "webp",
    "imageGuidanceScale": 3.5,
    "imageOutputQuality": 90,
    "additionalLoraScale": 1,
    "inferenceStepsCount": 28
}

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, you would replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action_id is set to the ID of the Generate Image with Inpainting action. The input payload is structured to match the action's requirements, and the API call is made using the requests library.

Conclusion

The alexdiazus/instaxmini12 Cognitive Actions provide a powerful way to generate customized images using advanced inpainting techniques. By integrating these actions into your applications, you can enhance user engagement and creativity. Whether you're building a fashion app, an art platform, or any other creative tool, the possibilities are endless. Start experimenting with the actions today and unlock new dimensions of image generation!