Create Stunning Images with the Project-IL-v2 Cognitive Actions

In the realm of artificial intelligence, the ability to generate high-quality images has become increasingly powerful and accessible. The Project-IL-v2 Cognitive Actions offer developers a robust solution for creating images tailored to specific prompts and customizable parameters. With these pre-built actions, you can enhance your applications with sophisticated image generation capabilities without the need for extensive machine learning expertise.
Prerequisites
Before diving into the integration of the Project-IL-v2 Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which you'll need to authenticate your requests.
- Basic familiarity with JSON formatting and HTTP requests.
Conceptually, authentication involves passing your API key in the headers of your requests. This ensures that your application can securely access the Cognitive Actions service.
Cognitive Actions Overview
Generate Image with Project-IL-v2
The Generate Image with Project-IL-v2 action allows you to create high-quality images based on customizable parameters. This action supports various features like adjustable image dimensions, prompt weighting, and batch sizes, enabling you to refine the image generation process effectively.
Input
The input for this action is structured as follows:
- seed (integer): The seed for random generation. Use -1 for a random seed. Default is -1.
- steps (integer): Number of steps for generation (1 to 100). Default is 34.
- width (integer): Width of the generated image (1 to 4096 pixels). Default is 1024.
- height (integer): Height of the generated image (1 to 4096 pixels). Default is 1024.
- prompt (string): Describes the desired scene or subject, using Compel weighting syntax. Default is a detailed prompt.
- modelType (string): Specifies the model version, defaulting to "Project-IL-v2".
- addPrePrompt (boolean): Prepend a pre-defined prompt for quality enhancement. Default is true.
- clipLayerSkip (integer): Number of CLIP layers to skip, with a minimum value of 1. Default is 2.
- excludedPrompt (string): Negative prompt specifying traits to avoid. Default is "nsfw, naked".
- imageBatchSize (integer): The number of images to generate per request (1 to 4). Default is 1.
- configurationScale (number): CFG scale for model adherence to the prompt (1 to 50). Default is 7.
- generationScheduler (string): Scheduler method for generation, impacting image quality. Default is "Euler a".
- guidanceNoiseRescale (number): Controls noise rescaling during generation (0 to 5). Default is 1.
- variationalAutoencoder (string): The VAE used during generation. Default is "default".
- progressiveAttentionGuidanceScale (number): Optimizes compatibility with CFG (0 to 50). Default is 0.
Example Input:
{
"seed": -1,
"steps": 34,
"width": 1024,
"height": 1024,
"prompt": "street, 1girl, dark-purple short hair, purple eyes, medium breasts, cleavage, casual clothes, smile, V",
"modelType": "Project-IL-v2",
"addPrePrompt": true,
"clipLayerSkip": 2,
"excludedPrompt": "nsfw, naked",
"imageBatchSize": 1,
"configurationScale": 7,
"generationScheduler": "Euler a",
"guidanceNoiseRescale": 1,
"variationalAutoencoder": "default",
"progressiveAttentionGuidanceScale": 0
}
Output
Upon successful execution, the action typically returns a URL pointing to the generated image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/c25e833d-880e-4989-a5d7-319b40fe5803/e8c930b8-f671-4bcd-bfc4-ad9a462bf4b3.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the Generate Image action in 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 = "648a5888-1f4e-442c-a777-1cdea7d9507e" # Action ID for Generate Image with Project-IL-v2
# Construct the input payload based on the action's requirements
payload = {
"seed": -1,
"steps": 34,
"width": 1024,
"height": 1024,
"prompt": "street, 1girl, dark-purple short hair, purple eyes, medium breasts, cleavage, casual clothes, smile, V",
"modelType": "Project-IL-v2",
"addPrePrompt": True,
"clipLayerSkip": 2,
"excludedPrompt": "nsfw, naked",
"imageBatchSize": 1,
"configurationScale": 7,
"generationScheduler": "Euler a",
"guidanceNoiseRescale": 1,
"variationalAutoencoder": "default",
"progressiveAttentionGuidanceScale": 0
}
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 payload variable contains the input data structured according to the action's requirements, and the response will include the URL of the generated image.
Conclusion
The Project-IL-v2 Cognitive Actions empower developers to integrate advanced image generation capabilities into their applications seamlessly. By leveraging the customizable parameters and pre-defined settings, you can create stunning visuals tailored to your users' needs. Explore the possibilities, and consider how these actions can enhance your projects with engaging and high-quality images!