Create Enchanting Ghibli-Style Videos with Cognitive Actions

23 Apr 2025
Create Enchanting Ghibli-Style Videos with Cognitive Actions

Creating captivating animated videos has become more accessible with the advent of advanced AI technologies. One such powerful tool is the wcarle/stable-diffusion-videos-ghibli API, which allows developers to generate mesmerizing Ghibli-style videos using the Stable Diffusion model. By leveraging pre-built Cognitive Actions, you can create unique animations that resonate with the whimsical charm of Ghibli films.

Prerequisites

Before diving into the implementation of the Cognitive Actions, ensure that you have the following set up:

  • API Key: You would need an API key to authenticate your requests. This key should be included in the headers of your requests.
  • Basic Understanding of JSON: Familiarity with JSON format will help you structure your input and understand the output.

Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Ghibli-Style Videos

The Generate Ghibli-Style Videos action creates videos by interpolating the latent space of Stable Diffusion using the Ghibli-Diffusion Model. This action is categorized under video-generation and can produce stunning animations that evoke the artistry of Studio Ghibli films.

Input

The input schema for this action consists of several fields:

  • randomSeeds: (string) Random seed values, separated by '|'. Use different seeds for each prompt. Leave blank for randomized seeds.
    • Example: "155 | 688"
  • inputPrompts: (string) A list of input prompts separated by '|'.
    • Example: "ghibli style open field with clouds (sunset) | ghibli style open field with clouds (night)"
  • numberOfSteps: (integer) Defines the number of steps for generating the interpolation video. Recommended values are 3-5 for testing and 60-200 for optimal results.
    • Example: 50
  • schedulerType: (string) Select the scheduler type for the generation process. Options include 'default', 'ddim', and 'klms'.
    • Example: "klms"
  • framesPerSecond: (integer) Sets the frame rate of the video, must be between 5 and 60.
    • Example: 15
  • guidanceScaleFactor: (number) The scaling factor for classifier-free guidance, accepting values from 1 to 20.
    • Example: 7.5
  • numberOfInferenceSteps: (integer) Specifies the number of denoising steps for each image generated, ranging from 1 to 500.
    • Example: 50

Example Input JSON:

{
  "randomSeeds": "155 | 688",
  "inputPrompts": "ghibli style open field with clouds (sunset) | ghibli style open field with clouds (night)",
  "numberOfSteps": 50,
  "schedulerType": "klms",
  "framesPerSecond": 15,
  "guidanceScaleFactor": 7.5,
  "numberOfInferenceSteps": 50
}

Output

The action typically returns a URL to the generated video. If successful, the output will look something like this:

Example Output:

https://assets.cognitiveactions.com/invocations/50f89e99-ae0a-47e1-a191-e975c9bc78df/382bb5c5-590b-4121-b2db-bfefbc18c064.mp4

Conceptual Usage Example (Python)

Here's a concise Python code snippet to illustrate how you might invoke this 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 = "ec6993e8-fb3e-4a5b-b96f-37034877edc2" # Action ID for Generate Ghibli-Style Videos

# Construct the input payload based on the action's requirements
payload = {
    "randomSeeds": "155 | 688",
    "inputPrompts": "ghibli style open field with clouds (sunset) | ghibli style open field with clouds (night)",
    "numberOfSteps": 50,
    "schedulerType": "klms",
    "framesPerSecond": 15,
    "guidanceScaleFactor": 7.5,
    "numberOfInferenceSteps": 50
}

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

In this snippet, you replace the API key and endpoint with your respective values. The action ID and input payload are structured according to the specifications provided.

Conclusion

The ability to generate Ghibli-style videos using the Cognitive Actions opens up a world of creative possibilities for developers. By simply defining a set of prompts and parameters, you can produce beautiful animations that capture the essence of beloved Ghibli films. To further enhance your application, consider experimenting with different input prompts, frame rates, and guidance scales. Happy coding!