Generate Stunning Images with the fofr/txt2img Cognitive Actions

21 Apr 2025
Generate Stunning Images with the fofr/txt2img Cognitive Actions

In today's digital landscape, generating high-quality images programmatically has become increasingly important for developers. The fofr/txt2img Cognitive Actions provide a powerful way to create images using advanced models with customizable parameters. By leveraging these pre-built actions, developers can focus on integrating image generation capabilities into their applications without delving deeply into the complexities of machine learning.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of JSON and Python for structuring your inputs and making API calls.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Customization

The Generate Image with Customization action allows you to create images based on a variety of advanced models such as RealVisXL, Juggernaut, Proteus, DreamShaper, and more. You can customize various parameters, including dimensions, prompts, sampling methods, and guidance scales, to fine-tune the image generation process for your specific needs.

  • Category: Image Generation

Input

The action requires the following parameters:

FieldTypeDescriptionDefault Value
seedIntegerSeed value for randomization (optional).N/A
modelStringSelect the base model for image generation.RealVisXL_V3.0
widthIntegerWidth of the generated image in pixels.768
heightIntegerHeight of the generated image in pixels.768
promptStringA directive that influences the image generation."a photo of an astronaut riding a unicorn"
schedulerStringChoose the scheduling method for the generation process.normal
samplerNameStringSelect the sampling algorithm to use.euler
guidanceScaleNumberControl the adherence to the prompt.7.5
negativePromptStringA negative prompt to guide image generation (optional)."ugly, disfigured, low quality, blurry, nsfw"
numberOfOutputsIntegerSpecify how many image variations to generate, from 1 to 10.1
disableSafetyCheckerBooleanToggle to disable the safety checker for produced images (optional).false
numberOfInferenceStepsIntegerSet the number of diffusion steps during image generation, between 1 and 100.30

Here is an example input payload:

{
  "model": "proteus_v02",
  "width": 768,
  "height": 768,
  "prompt": "a photo of an astronaut riding a unicorn",
  "scheduler": "normal",
  "samplerName": "euler",
  "guidanceScale": 7.5,
  "negativePrompt": "ugly, disfigured, low quality, blurry, nsfw",
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 20
}

Output

Upon successful execution, this action returns an array of URLs pointing to the generated images. Here’s an example of a typical output:

[
  "https://assets.cognitiveactions.com/invocations/02da5d68-a9d9-4f8d-b087-d63812d414a5/572c96b1-bdae-4b7c-8046-ec3a70d8be0d.png"
]

Conceptual Usage Example (Python)

Here is how you can invoke the Generate Image with Customization 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 = "ff2c0b6e-4563-4ddf-b0b0-dc5dbcd09b99" # Action ID for Generate Image with Customization

# Construct the input payload based on the action's requirements
payload = {
    "model": "proteus_v02",
    "width": 768,
    "height": 768,
    "prompt": "a photo of an astronaut riding a unicorn",
    "scheduler": "normal",
    "samplerName": "euler",
    "guidanceScale": 7.5,
    "negativePrompt": "ugly, disfigured, low quality, blurry, nsfw",
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 20
}

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 replace the API key and endpoint with your own. The action ID corresponds to the Generate Image with Customization action. The payload is structured to fit the input requirements, ensuring that you can generate images as intended.

Conclusion

The fofr/txt2img Cognitive Actions empower developers to seamlessly integrate high-quality image generation into their applications. By customizing various parameters, you can create stunning images tailored to your needs. Whether you’re building a creative tool, a game, or an innovative application, these Cognitive Actions provide the flexibility and power you need to enhance your projects. Start experimenting with them today and unlock new creative possibilities!