Generate High-Quality Images Effortlessly with rstars2/rstars-image3 Cognitive Actions

24 Apr 2025
Generate High-Quality Images Effortlessly with rstars2/rstars-image3 Cognitive Actions

In the realm of image generation, the rstars2/rstars-image3 Cognitive Actions provide developers with powerful tools to create high-quality images through innovative inpainting and image-to-image techniques. These pre-built actions simplify the process of generating visually appealing images by offering customizable options such as aspect ratio, resolution, and inference speed. Whether you need intricate details or faster processing, these actions cater to your specific requirements, enabling you to integrate advanced image capabilities into your applications seamlessly.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests and handling JSON data.

For authentication, you will typically pass your API key in the request headers to access the Cognitive Actions.

Cognitive Actions Overview

Generate Images with Inpainting

Purpose: This action allows you to generate high-quality images either by modifying existing images or creating new ones from a text prompt. You can customize various parameters such as aspect ratio, resolution, and inference speed, making it a versatile tool for developers.

Input

The input schema for this action requires the following fields:

  • prompt (required): The text prompt that guides the image generation process.
  • mask (optional): An image mask for inpainting mode.
  • seed (optional): An integer that sets a random seed for reproducible results.
  • image (optional): An input image for image-to-image generation.
  • model (optional): Select between "dev" (high detail) or "schnell" (faster processing).
  • width (optional): The width of the generated image (only if using a custom aspect ratio).
  • height (optional): The height of the generated image (only if using a custom aspect ratio).
  • aspectRatio (optional): Choose from predefined aspect ratios or set a custom one.
  • loraScale (optional): Controls the strength of the main LoRA application.
  • outputFormat (optional): The desired format for the output image (e.g., "webp", "jpg", "png").
  • guidanceScale (optional): Adjusts the guidance for the diffusion process.
  • outputQuality (optional): Sets the quality level of the output image.
  • numberOfOutputs (optional): Number of images to generate.

Example Input:

{
  "model": "dev",
  "prompt": "A hyper realistic photo of rajrstars with a cyberpunk background",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "outputFormat": "png",
  "guidanceScale": 3,
  "outputQuality": 80,
  "denoisingSteps": 28,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "outputMegapixels": "1",
  "additionalLoraScale": 1
}

Output

The action typically returns a URL pointing to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/0d5591df-3a31-4f3f-9dc0-914510ed2f36/053f2b7a-5511-4271-85ab-b6c46c16372d.png"
]

Conceptual Usage Example (Python)

Here’s how you might call this 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 = "ac166d60-4b36-46c0-a414-ef793ad44894"  # Action ID for Generate Images with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "A hyper realistic photo of rajrstars with a cyberpunk background",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "outputFormat": "png",
    "guidanceScale": 3,
    "outputQuality": 80,
    "denoisingSteps": 28,
    "enableFastMode": False,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "outputMegapixels": "1",
    "additionalLoraScale": 1
}

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 placeholder with your actual API key. The payload is constructed following the input schema and sent to the hypothetical endpoint to execute the action.

Conclusion

The rstars2/rstars-image3 Cognitive Actions empower developers to integrate robust image generation capabilities into their applications. By utilizing features like customizable prompts, aspect ratios, and model selection, developers can create images that meet their specific needs efficiently. To explore further, consider experimenting with various parameters to discover the best setups for your projects. Happy coding!