Enhance Your Applications with Image Generation Using 10xcrazyhorse/bonkfa Cognitive Actions

In today's digital landscape, the ability to generate and manipulate images programmatically can significantly enhance user experiences and open up new creative avenues. The 10xcrazyhorse/bonkfa API provides a powerful Cognitive Action that allows developers to generate custom images using inpainting techniques. This action enables you to create unique visuals based on textual prompts and existing images, making it an attractive option for applications in art, design, and content generation.
Prerequisites
Before diving into the implementation of this Cognitive Action, ensure you have the following:
- An API key for the Cognitive Actions platform, which will be required for authentication.
- Familiarity with making HTTP requests and handling JSON payloads.
Authentication typically involves passing the API key in the request headers to ensure secure access to the service.
Cognitive Actions Overview
Generate Custom Image Using Inpainting
This operation generates images using a specified prompt and an input image, supporting inpainting mode with various customization options such as aspect ratio, width, height, and image quality. It offers two models: 'dev' for high-quality outputs and 'schnell' for faster predictions.
- Category: Image Generation
Input
The input schema for this action requires a JSON object with the following fields:
- prompt (required): A textual description guiding the image generation.
- mask (optional): An image mask for inpainting mode.
- seed (optional): A random seed for reproducible generation.
- image (optional): An input image for image-to-image or inpainting mode.
- model (optional): Selects the inference model (default is 'dev').
- width (optional): Width of the generated image, only applicable if a custom aspect ratio is set.
- height (optional): Height of the generated image, only applicable if a custom aspect ratio is set.
- goFast (optional): Enables faster predictions with optimized models.
- guidanceScale (optional): Influences the diffusion process during image generation.
- numberOfOutputs (optional): Specifies the number of output images to generate.
Here's an example of the input JSON payload:
{
"model": "dev",
"width": 512,
"height": 512,
"prompt": "'BONKFA' is the blue shiba inu with white mouth\n- wearing swim trunks\n- american flag head tie, cool looks\n- BONKFA enjoying beautiful sunset\n- luxury yacht",
"loraScale": 1,
"outputFormat": "png",
"guidanceScale": 3.5,
"outputQuality": 90,
"promptStrength": 0.8,
"aspectRatioType": "1:1",
"numberOfOutputs": 1,
"additionalLoraScale": 1,
"numberOfInferenceSteps": 28
}
Output
The action typically returns a URL pointing to the generated image. Here's an example of the expected output:
[
"https://assets.cognitiveactions.com/invocations/f1632afe-0712-4b69-9366-32cb0a0ece47/dd489c8f-49d4-473d-85e6-0ff59e8d0185.png"
]
Conceptual Usage Example (Python)
The following conceptual Python code snippet demonstrates how to invoke the Generate Custom Image Using Inpainting action using a hypothetical Cognitive Actions execution endpoint.
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 = "0c25fa47-4572-4696-9be6-36340bf65759" # Action ID for Generate Custom Image Using Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"width": 512,
"height": 512,
"prompt": "'BONKFA' is the blue shiba inu with white mouth\n- wearing swim trunks\n- american flag head tie, cool looks\n- BONKFA enjoying beautiful sunset\n- luxury yacht",
"loraScale": 1,
"outputFormat": "png",
"guidanceScale": 3.5,
"outputQuality": 90,
"promptStrength": 0.8,
"aspectRatioType": "1:1",
"numberOfOutputs": 1,
"additionalLoraScale": 1,
"numberOfInferenceSteps": 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 example, replace the COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your actual API key and endpoint. The action ID for the Generate Custom Image Using Inpainting action is set, and the input payload is structured according to the requirements.
Conclusion
The 10xcrazyhorse/bonkfa Cognitive Action provides developers with a robust tool for generating custom images through inpainting. By leveraging the capabilities of this action, you can enhance your applications with visually engaging content tailored to specific prompts and user interactions. As you explore this functionality, consider experimenting with different input parameters to achieve your desired results. Happy coding!