Generate Stunning Images with maffuw/scrub-runners2 Cognitive Actions

23 Apr 2025
Generate Stunning Images with maffuw/scrub-runners2 Cognitive Actions

In today's digital landscape, the ability to create unique and captivating images is essential for many applications. The maffuw/scrub-runners2 API provides powerful Cognitive Actions to facilitate image generation through sophisticated image-to-image translation and inpainting techniques. By leveraging customizable model settings, developers can create high-quality images tailored to specific needs. In this article, we'll explore the "Generate Image Prediction" action in detail, including how to integrate it into your applications.

Prerequisites

To start using the Cognitive Actions from the maffuw/scrub-runners2 API, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Basic knowledge of JSON and how to make HTTP requests.
  • Familiarity with Python or another programming language to implement API calls.

Authentication typically involves passing the API key in the headers of your requests to ensure secure access to the services.

Cognitive Actions Overview

Generate Image Prediction

The Generate Image Prediction action allows you to create images using various methods, including image-to-image translation and inpainting. This action supports a wide range of customization options, enabling you to control aspects like image dimensions, formats, and model settings for optimized performance.

Input: The input for this action is structured as follows:

  • Required Field:
    • prompt (string): A descriptive text prompt that guides the image generation.
  • Optional Fields:
    • mask (string): URI of an image mask for inpainting mode.
    • seed (integer): Random seed for reproducibility.
    • image (string): URI of the input image for image processing.
    • width (integer): Width of the generated image in pixels (if aspect ratio is 'custom').
    • height (integer): Height of the generated image in pixels (if aspect ratio is 'custom').
    • goFast (boolean): Enable faster predictions using an optimized model.
    • aspectRatio (string): Aspect ratio for the generated images (default is "1:1").
    • numOutputs (integer): Number of images to generate (between 1 and 4).
    • outputFormat (string): File format of the output images (e.g., webp, jpg, png).
    • guidanceScale (number): Scale for guiding the diffusion process.
    • Additional fields for model configurations, LoRA weights, and more.

Example Input:

{
  "prompt": "WHITESRSNKRS with a bright pink sole close-up angle showing the shoe’s intricate details, including nurse characters, syringes, red hearts with heartbeat lines, stethoscopes, bandages, and pills. Set against a neutral backdrop, the lighting subtly emphasizes the texture of the shoe's surface. Photographed in 35mm style for clarity.",
  "loraScale": 1,
  "numOutputs": 4,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output: The result of executing this action will typically return an array of image URLs corresponding to the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/872dfe0a-86c6-4189-86cf-361d9eac2867/bb8b1feb-9727-4d99-b1c9-159e5c6e9c96.webp",
  "https://assets.cognitiveactions.com/invocations/872dfe0a-86c6-4189-86cf-361d9eac2867/f7cf71b3-75df-45b6-8700-8d91aa688984.webp",
  "https://assets.cognitiveactions.com/invocations/872dfe0a-86c6-4189-86cf-361d9eac2867/efbf8672-162f-4f89-b76c-13417d202520.webp",
  "https://assets.cognitiveactions.com/invocations/872dfe0a-86c6-4189-86cf-361d9eac2867/ec57790d-dabf-494f-aba7-dba2d4d5502c.webp"
]

Conceptual Usage Example (Python): Here’s how you might call the Generate Image Prediction 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 = "9aba07df-52e8-4f9a-918a-93843b8b74cb"  # Action ID for Generate Image Prediction

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "WHITESRSNKRS with a bright pink sole close-up angle showing the shoe’s intricate details, including nurse characters, syringes, red hearts with heartbeat lines, stethoscopes, bandages, and pills. Set against a neutral backdrop, the lighting subtly emphasizes the texture of the shoe's surface. Photographed in 35mm style for clarity.",
    "loraScale": 1,
    "numOutputs": 4,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 100,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "numInferenceSteps": 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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and adjust the endpoint as necessary. The action ID is set according to the Generate Image Prediction action, and the input payload follows the JSON schema described earlier.

Conclusion

The maffuw/scrub-runners2 API provides a versatile Generate Image Prediction action that empowers developers to create stunning images tailored to specific prompts. With various customization options at your disposal, this integration can significantly enhance the visual appeal of your applications. Start exploring the possibilities today, and consider how these actions can be applied to your projects for innovative results!