Enhance Your Applications with Image Generation using tuannha/easy-control Actions

25 Apr 2025
Enhance Your Applications with Image Generation using tuannha/easy-control Actions

In the realm of application development, the integration of advanced image generation capabilities can significantly enhance user experiences. The tuannha/easy-control API provides a powerful Cognitive Action designed for this purpose: generating composite images through customizable parameters. With the ability to control various aspects of the image synthesis process, developers can create visually appealing content tailored to specific requirements.

Prerequisites

To get started with the tuannha/easy-control API, you will need to have an API key for authentication. This key should be passed in the headers of your API requests to ensure secure communication. Ensure that you have the necessary setup to make HTTP requests to the Cognitive Actions endpoint.

Cognitive Actions Overview

Generate Image with Subject and Spatial Context

This action allows developers to generate a composite image using a given subject image along with a spatial context, guided by descriptive text prompts. Fine-tuning options such as seed, dimensions, and weights are available, providing a high level of customization.

  • Category: image-generation

Input

The input for this action is structured as follows:

{
  "seed": -1,
  "width": 1024,
  "height": 1024,
  "prompt": "A SKS in the library",
  "loraWeight": 1,
  "subjectImage": "https://replicate.delivery/pbxt/Mm003KufYhi45fTWcYglsPLLg0Hawqlef1sA1d0LuACcUMWF/subject_0.png",
  "guidanceScale": 3.5,
  "numInferenceSteps": 25
}
  • Required Fields:
    • prompt: A descriptive text guiding the image generation (e.g., "A SKS in the library").
    • subjectImage: URI of the primary subject image.
  • Optional Fields:
    • seed: Integer for random number generation (default is -1 for a random seed).
    • width: Width of the generated image in pixels (default is 1024).
    • height: Height of the generated image in pixels (default is 1024).
    • loraWeight: Weight affecting Lora influence on image generation (default is 1).
    • spatialImage: URI for spatial inpainting tasks (optional).
    • guidanceScale: Scale factor for guiding the generation process (default is 3.5).
    • numInferenceSteps: Total steps during the inference process (default is 25).

Output

Upon successful execution, this action returns the URI of the generated image. For example:

https://assets.cognitiveactions.com/invocations/c275b9b4-3d41-4e9f-9124-fa0ce29e832b/accf465c-0a3f-439c-aec1-1d59fe8f0f0d.png

This output allows you to access the newly generated image directly.

Conceptual Usage Example (Python)

Below is a conceptual Python snippet demonstrating how to invoke the Generate Image with Subject and Spatial Context action:

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 = "61712f64-71d9-4d2f-9379-3215aff1c415"  # Action ID for Generate Image with Subject and Spatial Context

# Construct the input payload based on the action's requirements
payload = {
    "seed": -1,
    "width": 1024,
    "height": 1024,
    "prompt": "A SKS in the library",
    "loraWeight": 1,
    "subjectImage": "https://replicate.delivery/pbxt/Mm003KufYhi45fTWcYglsPLLg0Hawqlef1sA1d0LuACcUMWF/subject_0.png",
    "guidanceScale": 3.5,
    "numInferenceSteps": 25
}

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}")

This code snippet illustrates how to send a request to the Cognitive Actions API, utilizing the action ID and the constructed input payload. The endpoint URL and request structure are hypothetical and should be replaced with the actual API endpoint.

Conclusion

The tuannha/easy-control Cognitive Action for generating images provides developers with a robust tool for creating customized visual content based on specific prompts and subject images. By leveraging this action, you can enhance your applications with engaging imagery, ultimately improving user interaction. Explore the various parameters to fully harness the capabilities of this image generation action and consider how it can fit into your development projects. Happy coding!