Enhance Image Generation with Attribute Control Actions

26 Apr 2025
Enhance Image Generation with Attribute Control Actions

In today's digital landscape, the ability to generate images tailored to specific requirements is invaluable. The "Attribute Control" service offers developers a powerful set of Cognitive Actions that enable precise manipulation of text-to-image (T2I) models. By leveraging these actions, you can enhance the flexibility and accuracy of artistic generation, allowing for continuous, subject-specific control over image attributes. This not only speeds up the creative process but also ensures that the images produced align closely with the desired outcomes.

Common use cases for Attribute Control include applications in marketing, where businesses can generate personalized visuals for campaigns, or in gaming, where character design can be customized based on specific attributes. Additionally, artists and designers can experiment with different styles and features, leading to innovative creations that resonate with their audience.

Prerequisites

To get started with Attribute Control, you will need a Cognitive Actions API key and a general understanding of how to make API calls.

Control T2I Model Attributes

The "Control T2I Model Attributes" action is designed to provide developers with the capability to influence the attributes of images generated by T2I models. This action solves the problem of limited control over image characteristics, allowing you to specify various features that the generated images should possess.

Input Requirements: To utilize this action, you will need to provide the following inputs:

  • Seed: An integer that initializes the random number generator for reproducibility (default: 0).
  • Prompt: A textual string to guide the generation process (default: "a photo of a beautiful man").
  • Delay Relative: A relative delay parameter for processing (default: 0.2).
  • Guidance Scale: A scaling factor that influences fidelity to the prompt (default: 7.5).
  • Pattern Target: The primary feature to focus on (default: "man").
  • Negative Prompt: A prompt to suppress certain features (default: empty).
  • Number of Images: The total number of images to generate (default: 5, max: 10).
  • Pretrained Adjustments: Select from predefined adjustments such as "person_age" or "person_fitness" (default: "person_age").

Expected Output: The output will be a list of URLs pointing to the generated images, each reflecting the specified attributes and adjustments.

Use Cases for this specific action:

  • Marketing Campaigns: Generate tailored images that match customer profiles or campaign themes.
  • Character Design in Games: Easily create characters with specific traits, enhancing player engagement.
  • Artistic Exploration: Artists can experiment with various attributes to discover new styles and forms, enriching their portfolios.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "76db60f1-c875-417f-b736-9398d70eac79" # Action ID for: Control T2I Model Attributes

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "seed": 0,
  "prompt": "a photo of a beautiful man",
  "delayRelative": 0.2,
  "guidanceScale": 7.5,
  "patternTarget": "man",
  "negativePrompt": "",
  "numberOfImages": 6,
  "pretrainedAdjustments": "person_age"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The Attribute Control actions significantly streamline the process of image generation, providing developers with the tools needed to produce high-quality visuals that meet specific requirements. By leveraging these capabilities, you can enhance creativity, personalize content, and explore new artistic avenues. As you integrate these actions into your projects, consider the diverse applications and the potential impact on your workflows. Start experimenting today to unlock new possibilities in image generation!