Enhance Your App's Creativity with Sunday Film's Cognitive Actions for Image Generation

In the age of digital content, the ability to generate high-quality images programmatically can be a game changer for developers. The Sunday Film's Cognitive Actions provide a powerful API for generating images using advanced diffusion models, allowing for customized configurations that cater to specific needs. In this article, we’ll explore how to leverage the Generate Inpainted Images action to create stunning images effortlessly.
Prerequisites
Before diving into the integration of Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making HTTP requests and handling JSON data.
Authentication typically involves passing your API key in the headers of your requests to access the functionalities securely.
Cognitive Actions Overview
Generate Inpainted Images
The Generate Inpainted Images action enables the creation of high-quality images by inpainting existing images or generating new ones based on textual prompts. This action is optimized for both speed and quality, supporting various configurations for customized outputs.
Input
The input for this action requires a JSON payload that can include a variety of parameters. Below are the key fields:
- prompt (required): A textual description of the image to generate.
- mask: URI of the image mask used in inpainting mode.
- seed: An integer to seed the random number generator for reproducible results.
- image: URI of the input image used for transformation.
- width & height: Dimensions of the generated image (if aspect_ratio is set to custom).
- imageFormat: Format for the output image (default: webp).
- outputCount: Number of images to generate (1 to 4).
- imageQuality: Quality setting for the output image.
- guidanceScale: Scale for the diffusion process.
- mainLoraScale: Strength for the main LoRA model.
Here’s an example of a complete input payload:
{
"seed": 573452,
"prompt": "a cell phone, prop, illustration style, lofi anime art, minimalist, gauche, ligne claire",
"imageFormat": "png",
"outputCount": 1,
"imageQuality": 90,
"guidanceScale": 3.5,
"mainLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"inferenceStepCount": 35,
"additionalLoraScale": 1
}
Output
The output of this action typically returns a URL to the generated image. Here’s an example of a successful output:
[
"https://assets.cognitiveactions.com/invocations/bdbc55dd-284f-4bba-bcce-e1abed93d8db/ca92fb00-e19e-4855-b12a-93a75c8cc418.png"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet demonstrating how to call the Cognitive Actions endpoint for generating inpainted images:
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 = "1dc80022-311f-4ad8-9ba8-8df59bd3cc65" # Action ID for Generate Inpainted Images
# Construct the input payload based on the action's requirements
payload = {
"seed": 573452,
"prompt": "a cell phone, prop, illustration style, lofi anime art, minimalist, gauche, ligne claire",
"imageFormat": "png",
"outputCount": 1,
"imageQuality": 90,
"guidanceScale": 3.5,
"mainLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"inferenceStepCount": 35,
"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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured based on the input requirements of the action, ensuring that you provide the necessary parameters to generate the desired image.
Conclusion
The Generate Inpainted Images action from Sunday Film's Cognitive Actions empowers developers to create stunning images with minimal effort. By leveraging customizable inputs like prompts, aspect ratios, and image qualities, you can enhance your applications and provide users with captivating visual content. Start experimenting with these capabilities today to unlock new creative possibilities!