Generate Stunning Images with Custom Parameters Using AI

25 Apr 2025
Generate Stunning Images with Custom Parameters Using AI

Creating captivating images from textual descriptions has never been easier, thanks to the powerful capabilities of the Art Cognitive Actions. This service allows developers to generate images using text prompts, leveraging advanced techniques like inpainting and image-to-image generation. With customizable settings for image dimensions, aspect ratios, and quality, the Art API streamlines the image creation process, enabling rapid and efficient content generation.

Imagine the possibilities: designing unique artwork for a game, creating custom illustrations for educational materials, or generating visuals for marketing campaigns—all tailored to your specifications. The flexibility and speed provided by these Cognitive Actions empower developers to bring their creative visions to life quickly and effectively.

Prerequisites

Before you dive into using the Art API, make sure you have a Cognitive Actions API key and a basic understanding of how to make API calls.

Generate Images with Custom Parameters

This action allows you to generate images from text prompts, utilizing either inpainting or image-to-image modes. It offers a range of customizable parameters to tailor the output according to your needs.

Purpose

The "Generate Images with Custom Parameters" action solves the challenge of creating high-quality images that match specific requirements, whether for artistic projects or practical applications.

Input Requirements

The input for this action is a structured object that requires a prompt to guide the image generation. Additional options include:

  • mask: (URI) Image mask for inpainting mode.
  • seed: (integer) For reproducibility of output.
  • image: (URI) Input image for image-to-image or inpainting mode.
  • width: (integer) Width of the generated image.
  • height: (integer) Height of the generated image.
  • goFast: (boolean) Option for accelerated predictions.
  • guidanceScale: (number) Affects the guidance of the diffusion process.
  • outputQuality: (integer) Quality of the saved output images.
  • inferenceModel: (string) Model selection for inference.
  • promptStrength: (number) Impact of the prompt on image generation.
  • numberOfOutputs: (integer) Number of images to generate.
  • imageAspectRatio: (string) Aspect ratio for the generated image.
  • imageOutputFormat: (string) File format for the output images.

Expected Output

The expected output is a URL pointing to the generated image, allowing you to access and utilize the visual content easily.

Use Cases for this Action

  • Art and Design: Create unique illustrations and artwork for creative projects.
  • Marketing: Generate customized images for promotional materials or social media campaigns.
  • Education: Develop engaging visual content for educational resources or presentations.
  • Game Development: Design character or environment art tailored to specific themes or narratives.
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 = "da7c1fab-9463-4e0b-afa6-61f9628cd20c" # Action ID for: Generate Images with Custom Parameters

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "Elfenmädchen mit weißem, zerzaustem Haar",
  "guidanceScale": 3.5,
  "outputQuality": 95,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "imageAspectRatio": "9:16",
  "imageOutputFormat": "jpg",
  "additionalLoraScale": 0.8,
  "loraApplicationScale": 1,
  "numberOfInferenceSteps": 28
}

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 Art Cognitive Actions provide developers with a robust toolset for generating stunning images that are tailored to their specific needs. With customizable parameters and fast generation capabilities, you can easily create visuals for a variety of applications, from marketing to education and beyond. Explore the possibilities and enhance your projects by integrating these powerful image generation capabilities today!