Generate Stunning Images with Cognitive Actions from sanjeeva30/gunawardena

In today's digital landscape, the ability to create captivating images on demand can significantly enhance user engagement and creativity. The sanjeeva30/gunawardena spec provides a robust set of Cognitive Actions designed to generate high-quality images using detailed prompts and optional image masks for inpainting. This article will guide you through the integration of the Generate Image with Inpainting action, empowering you to harness the full potential of image generation in your applications.
Prerequisites
Before you dive in, ensure you have the following set up:
- An API key for accessing the Cognitive Actions platform.
- Basic knowledge of making HTTP requests and handling JSON data.
For authentication, you will typically include your API key in the headers of your requests, allowing you to securely access the Cognitive Actions.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create detailed images based on input prompts. You can also provide optional image masks to refine the generation process. This action supports a fast mode for quicker predictions and allows customization of output settings like quality and aspect ratio.
Input
The input to this action requires a JSON object structured according to the following schema:
{
"prompt": "string", // Required
"mask": "string", // Optional, URI of the image mask
"seed": "integer", // Optional, for reproducibility
"image": "string", // Optional, URI for image-to-image mode
"width": "integer", // Optional, width of the generated image
"height": "integer", // Optional, height of the generated image
"goFast": "boolean", // Optional, for faster predictions
"numOutputs": "integer", // Optional, number of outputs
"guidanceScale": "number", // Optional, guidance scale for diffusion
"outputQuality": "integer", // Optional, quality of output images
"imageAspectRatio": "string", // Optional, aspect ratio for the image
"imageOutputFormat": "string", // Optional, output image format
// Additional fields...
}
Example Input:
{
"goFast": false,
"prompt": "a close-up realistic photo of gunawardena riding a big HarleyDavidson on a beach road during sunset hour, no helmet, face clearly visible",
"loraScale": 1,
"numOutputs": 4,
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"generationModel": "dev",
"imageMegapixels": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "jpg",
"numInferenceSteps": 28
}
Output
Upon successful execution, this action returns an array of URLs pointing to the generated images. Here's an example of the expected output:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/cb3c1863-5466-4c22-b4c7-e9a0dda11b75/d054d58e-4ad1-485e-ba42-13726b78299f.jpg",
"https://assets.cognitiveactions.com/invocations/cb3c1863-5466-4c22-b4c7-e9a0dda11b75/f605367d-b26b-457e-aa0e-f074f535b1f7.jpg",
"https://assets.cognitiveactions.com/invocations/cb3c1863-5466-4c22-b4c7-e9a0dda11b75/d8eccb28-6c7b-4336-9494-3f4d863052fe.jpg",
"https://assets.cognitiveactions.com/invocations/cb3c1863-5466-4c22-b4c7-e9a0dda11b75/cf9255ac-df41-417a-8b22-4dc158829baa.jpg"
]
Conceptual Usage Example (Python)
Here’s how you can conceptually implement a call to this 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 = "e24ba714-30d3-40cc-a026-861e97d20b0b" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"goFast": false,
"prompt": "a close-up realistic photo of gunawardena riding a big HarleyDavidson on a beach road during sunset hour, no helmet, face clearly visible",
"loraScale": 1,
"numOutputs": 4,
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"generationModel": "dev",
"imageMegapixels": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "jpg",
"numInferenceSteps": 28
}
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_KEYwith your actual API key. - The
action_idis set to the ID of the Generate Image with Inpainting action. - The
payloadis structured according to the input schema, ensuring all required fields are included.
Conclusion
The Generate Image with Inpainting action from the sanjeeva30/gunawardena spec opens up exciting possibilities for developers looking to integrate advanced image generation capabilities into their applications. By leveraging this action, you can create unique visual content tailored to your users' needs.
As a next step, consider experimenting with different prompts and output settings to discover the full potential of image generation in your projects!