Create Stunning Ghibli-Style Images with AI Actions

26 Apr 2025
Create Stunning Ghibli-Style Images with AI Actions

The Ghibli Cognitive Actions offer developers a powerful way to generate visually captivating images inspired by the enchanting aesthetic of Studio Ghibli films. By leveraging a fine-tuned model based on iconic Ghibli stills, these actions enable the creation of unique images with configurable features, allowing for a high degree of customization. Whether you’re an artist seeking inspiration, a game developer looking to enhance visual storytelling, or a marketer wanting to add a whimsical touch to your campaigns, the Ghibli actions simplify the image generation process and enhance your creative projects.

Prerequisites

Before you begin, ensure you have a valid Cognitive Actions API key and a basic understanding of making API calls to utilize these powerful image generation features.

Generate Ghibli-Style Image

Purpose

The "Generate Ghibli-Style Image" action allows users to create images that reflect the distinctive charm and artistry of Studio Ghibli. This action solves the challenge of generating high-quality, aesthetically pleasing images tailored to specific prompts, enabling users to bring their imaginative concepts to life.

Input Requirements

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

  • prompt: A text prompt guiding the image generation (e.g., "illustration of a heron in TOK style").
  • image: A URI for the input image, applicable in img2img or inpainting modes.
  • mask: A URI for the input mask used in inpainting mode, defining which areas to preserve or alter.
  • width: The desired width of the output image in pixels (default is 1024).
  • height: The desired height of the output image in pixels (default is 1024).
  • numberOfOutputs: The number of images to generate (1 to 4).
  • guidanceScale: A scale for classifier-free guidance (1 to 50).
  • promptStrength: The strength of the input prompt in image transformation.
  • loraScale: An additive scale for model adjustments (0 to 1).
  • schedulingMethod: Algorithm for scheduling the generation process.
  • numInferenceSteps: Total number of denoising steps applied during generation.

Expected Output

The action will return a generated image URL, which can be used directly in your applications. For example, a successful output might look like this:

  • https://assets.cognitiveactions.com/invocations/d8aea680-1c8f-403c-8472-3a7111d1357c/c3e65c46-0dad-44f8-8cb4-e9c9cc578b3a.png

Use Cases for this Specific Action

  • Art and Design: Artists can leverage this action to create Ghibli-inspired artwork for personal projects or client work.
  • Game Development: Game developers can generate unique assets that fit within a Ghibli-style narrative or aesthetic, enhancing the immersive experience of their games.
  • Marketing Campaigns: Marketers can produce whimsical visuals that capture attention and resonate with audiences, perfect for social media content or promotional materials.
  • Storytelling: Writers and storytellers can visualize scenes from their narratives, adding a rich visual layer to their storytelling efforts.
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 = "161f7785-9833-4641-bd24-77bb809f4221" # Action ID for: Generate Ghibli-Style Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 1024,
  "height": 1024,
  "prompt": "illustration of a heron in TOK style ",
  "loraScale": 0.6,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.8,
  "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

The Ghibli Cognitive Actions empower developers and creatives to generate stunning, unique images that capture the essence of Studio Ghibli’s beloved aesthetic. With customizable parameters and straightforward input requirements, this action opens up a world of possibilities for art, storytelling, and marketing. To get started, explore the various input options to tailor the image generation to your specific needs and watch your creative visions come to life!