Create Stunning Animations with the Replicate/Goo Cognitive Actions

22 Apr 2025
Create Stunning Animations with the Replicate/Goo Cognitive Actions

In the realm of digital content creation, the ability to generate captivating animations can elevate your applications significantly. The Replicate/Goo API offers a unique Cognitive Action: Generate Goo Animation. This action allows developers to create mesmerizing goo-like animations with customizable parameters, delivering outputs in various formats, including images and videos. By harnessing these pre-built actions, developers can save time and effort while integrating engaging visual effects into their applications.

Prerequisites

Before diving into the implementation, ensure you have the following:

  • An API key for the Replicate/Goo Cognitive Actions platform.
  • Basic knowledge of making HTTP requests in Python.

Authentication typically involves passing your API key in the request headers to securely access the service.

Cognitive Actions Overview

Generate Goo Animation

Description:
This action creates a goo-like animation effect that can be customized in terms of speed, depth, scale, and output format. It supports generating outputs in image formats (PNG, JPEG, TIFF) or as an MP4 video.

Category: Video Generation

Input

The action requires a JSON payload structured according to the following schema:

{
  "seed": -1,
  "depth": 3,
  "scale": 1,
  "speed": 2,
  "width": 512,
  "format": "png",
  "height": 512,
  "numberOfFrames": 600,
  "framesPerSecond": 60
}

Required Fields:

  • format: The output file format (options: png, jpeg, tiff, mp4). Default is png.
  • width: Width of the output image in pixels (range: 1 to 4096). Default is 512.
  • height: Height of the output image in pixels (range: 1 to 4096). Default is 512.

Optional Fields:

  • seed: Seed for the random number generator (default is -1).
  • depth: Level of detail or recursion depth (default is 3).
  • scale: Scaling factor for dimensions (default is 1).
  • speed: Speed of the animation effect (range: 0 to 10, default is 2).
  • numberOfFrames: Total frames for video output (only for mp4, default is 600).
  • framesPerSecond: Frame rate for video output (only for mp4, default is 60).

Example Input:

{
  "depth": 3,
  "scale": 2,
  "speed": 2,
  "width": 1024,
  "format": "mp4",
  "height": 1024,
  "numberOfFrames": 600,
  "framesPerSecond": 60
}

Output

Upon successful execution, the action typically returns a URL pointing to the generated animation. For example:

https://assets.cognitiveactions.com/invocations/2a13a853-f2e0-4cb9-8085-d4337e1ef112/c3746423-1f3d-4eb5-90bf-608f1344ecce.mp4

This URL can be used to access the created animation directly.

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how you might invoke the Generate Goo Animation 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 = "521520dd-e972-4426-87b5-d67ecef019fe" # Action ID for Generate Goo Animation

# Construct the input payload based on the action's requirements
payload = {
    "depth": 3,
    "scale": 2,
    "speed": 2,
    "width": 1024,
    "format": "mp4",
    "height": 1024,
    "numberOfFrames": 600,
    "framesPerSecond": 60
}

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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID corresponds to the Generate Goo Animation action, and the payload is structured according to the required input schema. The code handles potential errors and prints the resulting output URL.

Conclusion

The Generate Goo Animation action from the Replicate/Goo API opens up new opportunities for developers looking to enhance their applications with dynamic visual content. By leveraging this Cognitive Action, you can easily create stunning animations tailored to your specifications. Consider exploring additional use cases or integrating other Cognitive Actions to further enrich your projects. Happy coding!