Create Stunning Images with Dante's Image Generation Actions

26 Apr 2025
Create Stunning Images with Dante's Image Generation Actions

Dante is an innovative service that empowers developers to generate and refine images using advanced AI techniques. With its Cognitive Actions, you can create custom images tailored to your specifications, enhancing visual content for various applications. Whether you're working on marketing materials, social media graphics, or digital art, Dante simplifies the image creation process, saving you time while delivering high-quality results.

Imagine being able to generate unique images based on your creative prompts or to refine existing images with precision. Dante supports diverse use cases, from generating artwork for campaigns to creating personalized avatars or illustrations. By leveraging AI, you can significantly boost your productivity and creativity without needing extensive graphic design skills.

Prerequisites

To get started with Dante, you'll need an API key for Cognitive Actions and a basic understanding of how to make API calls. This will enable you to harness the full potential of the image generation capabilities.

Generate and Refine Images

The "Generate and Refine Images" action allows you to create custom AI-enhanced images by specifying various parameters such as input images, prompts, dimensions, and more. This action is particularly useful for developers looking to automate the image creation process or enhance existing visuals with AI.

  • Purpose: This action solves the challenge of generating high-quality images tailored to specific requirements, whether for new creations or refining existing ones. It offers flexibility and control over the image generation process.
  • Input Requirements: The input for this action is a composite request that includes fields such as:
    • image (URI): The input image for processing (for img2img or inpaint mode).
    • mask (URI): A mask image for inpaint mode.
    • prompt (string): Descriptive text guiding the image generation.
    • width (integer): Specifies the output image width in pixels.
    • height (integer): Specifies the output image height in pixels.
    • numOutputs (integer): The number of output images to generate (1 to 4).
    • Additional parameters like guidanceScale, promptStrength, and applyWatermark enhance the customization of the output.
  • Expected Output: The output will be an array of generated image URIs that can be directly used in applications or further processed. For example:
    • ["https://assets.cognitiveactions.com/invocations/.../image1.png", "https://assets.cognitiveactions.com/invocations/.../image2.png"]
  • Use Cases for this specific action:
    • Marketing: Generate eye-catching visuals for promotional campaigns that resonate with your target audience.
    • Content Creation: Create unique images for blogs, articles, or social media posts that grab attention and engage viewers.
    • Art and Design: Produce original artworks or illustrations based on specific themes or ideas, enabling artists to explore new creative avenues.
    • Gaming: Develop custom assets for video games, such as character designs or environments, tailored to specific narratives or styles.
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 = "1fbb6ae0-3025-4a1f-854f-8d54478eeeb2" # Action ID for: Generate and Refine Images

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "image": "https://replicate.delivery/pbxt/LbmPvr3y5MBKdfgcQFD2HNbZbTSJEsxgajwerQoKV8EZHEDH/Nevaeh%20%2812%29.jpg",
  "width": 1024,
  "height": 1024,
  "prompt": " fire and smoke, TOK comes out swinging, in the distance you see @BRKN @nevaeh",
  "loraScale": 0.6,
  "numOutputs": 2,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "schedulingMethod": "K_EULER",
  "numInferenceSteps": 50
}

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

Dante's image generation capabilities offer developers a powerful tool for creating and refining images effortlessly. By leveraging AI, you can enhance your projects with unique visuals that captivate audiences and streamline your workflow. Whether you are generating images for marketing, content creation, or artistic endeavors, Dante provides the flexibility and ease of use you need to bring your creative visions to life.

To get started, sign up for your API key and explore the various parameters to maximize the potential of your image generation experience with Dante!