Create Stunning Visual Anagrams with the chigozienri/visual-anagrams Cognitive Actions

Visual anagrams can transform your creative projects by generating engaging and innovative images. The chigozienri/visual-anagrams API provides powerful Cognitive Actions that allow developers to create multi-view optical illusions that shift their appearance based on various inputs. This article will guide you through how to use these actions effectively in your applications.
Introduction
The chigozienri/visual-anagrams API is a specialized service designed for image generation with a unique twist. By utilizing this API, developers can generate images that change their identity or appearance through transformations like rotation, color inversion, or rearrangement. The pre-built actions in this API simplify the process of creating complex visual effects, allowing you to focus on building your application rather than dealing with intricate algorithms.
Prerequisites
Before you start using the Cognitive Actions, ensure that you have:
- An API key for accessing the Cognitive Actions platform.
- Basic knowledge of JSON and how to perform API requests.
For authentication, you will typically pass the API key in the headers of your requests.
Cognitive Actions Overview
Generate Multi-View Optical Illusions
This action generates images that transform their appearance or identity when altered through various actions. It creates visual anagrams and multi-view illusions, providing a unique perspective shift.
- Category: Image Generation
Input
The input to this action requires the following fields:
| Field | Type | Description | Example |
|---|---|---|---|
| seed | Integer | Optional seed for random number generation. Leave empty for a random seed each time. | 0 |
| style | String | A prefix for the visual style prompt, such as 'an oil painting of'. | "an oil painting of " |
| video | Boolean | Determines if video output is enabled. Default is true. | true |
| views | String | Comma-separated list of views (identity, flip, rotate_cw, etc.). Must match the number of prompts. | "identity, jigsaw" |
| prompts | String | Comma-separated list of textual prompts for generation. | "a rabbit, a coffee cup" |
| numberOfSamples | Integer | The number of samples to generate. Default is 1. | 1 |
| guidanceScalePrimary | Number | Primary guidance scale for controlling the strength of the text-to-image transformation. | 10 |
| guidanceScaleSecondary | Number | Secondary guidance scale for controlling the strength of the transformation. | 10 |
| numberOfInferenceStepsPrimary | Integer | Number of inference steps for the primary process. Default is 30. | 30 |
| numberOfInferenceStepsSecondary | Integer | Number of inference steps for the secondary process. Default is 30. | 30 |
Example Input:
{
"seed": 0,
"style": "an oil painting of ",
"video": true,
"views": "identity, jigsaw",
"prompts": "a rabbit, a coffee cup",
"numberOfSamples": 1,
"guidanceScalePrimary": 10,
"guidanceScaleSecondary": 10,
"numberOfInferenceStepsPrimary": 30,
"numberOfInferenceStepsSecondary": 30
}
Output
The action typically returns an array of image and video URLs as output. Here’s what the output might look like:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/b5d9b581-2346-4db9-ae41-c84d66852a11/2048ae8a-2832-4832-8c3a-05331f6bd6eb.png",
"https://assets.cognitiveactions.com/invocations/b5d9b581-2346-4db9-ae41-c84d66852a11/bafd7457-4cff-47dc-b18d-2f13ee8821c1.png",
"https://assets.cognitiveactions.com/invocations/b5d9b581-2346-4db9-ae41-c84d66852a11/45f6b11e-9483-4810-8dfb-98408727e929.mp4"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how to call the Generate Multi-View Optical Illusions action using Python:
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 = "d9bc9f8a-7f08-44c9-86e4-4066ae423d92" # Action ID for Generate Multi-View Optical Illusions
# Construct the input payload based on the action's requirements
payload = {
"seed": 0,
"style": "an oil painting of ",
"video": True,
"views": "identity, jigsaw",
"prompts": "a rabbit, a coffee cup",
"numberOfSamples": 1,
"guidanceScalePrimary": 10,
"guidanceScaleSecondary": 10,
"numberOfInferenceStepsPrimary": 30,
"numberOfInferenceStepsSecondary": 30
}
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 code snippet, replace the API key and endpoint with your actual credentials. The action_id is set for the Generate Multi-View Optical Illusions action, and the payload is structured according to the input schema described earlier.
Conclusion
The chigozienri/visual-anagrams Cognitive Actions provide an innovative way to create unique visual content for your applications. By leveraging the Generate Multi-View Optical Illusions action, you can easily produce captivating images that transform based on user interactions or other parameters. Start experimenting with these actions today to enhance the visual appeal of your projects!