Unleashing Creativity: Generate Stunning Images with tokaito14/color Cognitive Actions

In the realm of image generation, the tokaito14/color Cognitive Actions offer developers an impressive set of tools to create high-quality images from textual prompts. These Cognitive Actions enable you to harness advanced features like image masking, aspect ratios, and a choice of model settings to optimize the generation process. With these pre-built actions, developers can seamlessly integrate powerful image generation capabilities into their applications, enhancing user experiences and fostering creativity.
Prerequisites
Before diving into the integration of tokaito14/color Cognitive Actions, ensure you have the following:
- An API key for accessing the Cognitive Actions platform. This key will allow you to authenticate your requests to the service.
- Basic familiarity with making HTTP requests and handling JSON payloads in your application.
Conceptually, authentication typically involves including your API key in the request headers. This can be structured as follows:
Authorization: Bearer YOUR_COGNITIVE_ACTIONS_API_KEY
Cognitive Actions Overview
Generate Image with Prompt and Masking
Description: This action generates high-quality images based on a textual prompt and allows for optional image masking for inpainting. It offers various customization options, including aspect ratios, model settings (dev and schnell), and an optimized fast generation mode.
Category: image-generation
Input
The input for this action is structured as a JSON object. Here are the required and optional fields:
- Required:
prompt(string): Defines the text prompt for the generated image.
- Optional:
mask(string): A URI for the image mask used in inpainting mode.seed(integer): A seed for random number generation.image(string): A URI to the input image for image-to-image or inpainting mode.model(string): Selects the model for inference (devorschnell).width(integer): Specifies the width of the generated image (when aspect ratio is 'custom').height(integer): Specifies the height of the generated image (when aspect ratio is 'custom').aspectRatio(string): Defines the aspect ratio of the generated image.outputCount(integer): Number of images to generate.outputFormat(string): File format of the generated images.guidanceScale(number): Sets the guidance scale for the diffusion process.outputQuality(integer): Specifies the quality of the output images.promptStrength(number): Determines prompt intensity in img2img processing.inferenceStepCount(integer): Number of denoising steps.- And several other parameters for advanced customization.
Example Input:
{
"model": "dev",
"prompt": "trend on artstation, close-up, charming brunette in a white baseball cap, in a pearl jacket, long hair going in a beautiful lace dress, floral embroidery, chiffon + mesh, in the style of Khokhloma+Dolce Gabbana, pencil drawing in color, pastel tones cream, coffee, pale aquamarine, white, sky, pink, silver, diamonds, hyperrealism, realistic, backlight in the middle of the frame, light, haze, sharp focus on the face, detailing of the face, body and clothes, surrealism 64k, Klod Mone, epic royal background, big royal uncropped crown, royal jewelry, robotic, nature, full shot, symmetrical, Greg Rutkowski, Charlie Bowater, Beeple, Unreal 5, hyperrealistic, dynamic lighting, fantasy art",
"aspectRatio": "1:1",
"outputCount": 1,
"outputFormat": "jpg",
"guidanceScale": 3.5,
"outputQuality": 95,
"promptStrength": 0.8,
"primaryLoraScale": 1,
"inferenceStepCount": 28,
"additionalLoraScale": 1
}
Output
Upon successful execution, the action typically returns a link to the generated image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/3b8afc29-0ecb-437a-8053-54d9b3fddcc2/e76ddf7a-9274-480e-99eb-0c17b09fe410.jpg"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet showing how you might call the Cognitive Actions endpoint to execute 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 = "8ece5db5-316f-4f4f-b978-6f56c1c4db1f" # Action ID for Generate Image with Prompt and Masking
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "trend on artstation, close-up, charming brunette in a white baseball cap, in a pearl jacket, long hair going in a beautiful lace dress, floral embroidery, chiffon + mesh, in the style of Khokhloma+Dolce Gabbana, pencil drawing in color, pastel tones cream, coffee, pale aquamarine, white, sky, pink, silver, diamonds, hyperrealism, realistic, backlight in the middle of the frame, light, haze, sharp focus on the face, detailing of the face, body and clothes, surrealism 64k, Klod Mone, epic royal background, big royal uncropped crown, royal jewelry, robotic, nature, full shot, symmetrical, Greg Rutkowski, Charlie Bowater, Beeple, Unreal 5, hyperrealistic, dynamic lighting, fantasy art",
"aspectRatio": "1:1",
"outputCount": 1,
"outputFormat": "jpg",
"guidanceScale": 3.5,
"outputQuality": 95,
"promptStrength": 0.8,
"primaryLoraScale": 1,
"inferenceStepCount": 28,
"additionalLoraScale": 1
}
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, you replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is constructed to meet the action's requirements, and the response is processed to display the generated image link.
Conclusion
The tokaito14/color Cognitive Actions empower developers to create stunning images with ease. By leveraging the capabilities of the Generate Image with Prompt and Masking action, you can enhance your applications, providing users with the ability to generate unique images from descriptive text prompts. Next steps might include experimenting with different prompts, exploring image masking, or integrating additional parameters to customize your image generation further. Dive into your creative journey with these powerful tools!