Generating Stunning Images with Cognitive Actions from mikimel/mikiai

In today's digital landscape, the ability to generate images programmatically has become a game-changer for developers. The mikimel/mikiai API offers an exciting set of Cognitive Actions designed for image generation, specifically focusing on inpainting and image-to-image conversion. These pre-built actions enable developers to create custom images with a variety of settings, enhancing creativity and productivity in applications.
Prerequisites
Before diving into using the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Basic knowledge of making API calls and handling JSON payloads.
To authenticate your requests, you will typically need to pass the API key in the headers of your requests.
Cognitive Actions Overview
Generate Image Using Inpainting
Description: This operation generates images using image-to-image conversion or inpainting with options for custom settings, such as aspect ratio, output format, and quality. It supports different LoRA weight sources and model selections to optimize for speed or quality.
Category: image-generation
Input
The input for this action requires the following fields based on the provided schema:
- prompt (required): A textual description used to generate the image.
Example:"mikiai is sitting in a coffee shop working on his laptop" - Optional fields include:
- mask: URI of the image mask for inpainting mode.
- seed: Integer seed for reproducibility.
- image: URI of the input image for image-to-image or inpainting mode.
- width: Width of the generated image in pixels (256 to 1440).
- height: Height of the generated image in pixels (256 to 1440).
- isFastMode: Enable for faster image generation.
- imageFormat: Format of the output image (webp, jpg, png).
- outputCount: Number of output images to generate (1 to 4).
- imageQuality: Quality of the output images (0 to 100).
- inferenceModel: Model for inference (dev, schnell).
- imageAspectRatio: Aspect ratio of the generated image.
- mainLoraStrength: Influence of the main LoRA.
- inferenceStepCount: Number of denoising steps (1 to 50).
- textPromptIntensity: Strength of the text prompt.
- additionalLoraStrength: Additional LoRA influence.
- diffusionGuidanceScale: Guidance scale for the diffusion process.
Example Input:
{
"prompt": "mikiai is sitting in a coffee shop working on his laptop",
"imageFormat": "jpg",
"outputCount": 1,
"imageQuality": 90,
"inferenceModel": "dev",
"imageAspectRatio": "16:9",
"mainLoraStrength": 1,
"inferenceStepCount": 28,
"textPromptIntensity": 0.8,
"additionalLoraStrength": 1,
"diffusionGuidanceScale": 3.5
}
Output
The action typically returns a URL pointing to the generated image. For example:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/3cf63ce3-9898-48ba-bba9-209306a4c36a/323b6728-ebbb-4733-bc78-82de71f1dc35.jpg"
]
Conceptual Usage Example (Python)
Here's how you might call the Generate Image Using Inpainting 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 = "33b13da7-10b8-4dd6-a671-724a1fda4d59" # Action ID for Generate Image Using Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "mikiai is sitting in a coffee shop working on his laptop",
"imageFormat": "jpg",
"outputCount": 1,
"imageQuality": 90,
"inferenceModel": "dev",
"imageAspectRatio": "16:9",
"mainLoraStrength": 1,
"inferenceStepCount": 28,
"textPromptIntensity": 0.8,
"additionalLoraStrength": 1,
"diffusionGuidanceScale": 3.5
}
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 the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable contains the input data structured according to the action's requirements. The API call is made to a hypothetical endpoint, with the action ID and input payload passed in the request.
Conclusion
The Cognitive Actions from mikimel/mikiai provide a powerful toolkit for developers looking to integrate image generation capabilities into their applications. With options for customization and fine-tuning, you can create unique images tailored to your specific needs. Consider exploring additional use cases, such as integrating these actions into content creation tools, art applications, or gaming environments to fully leverage their potential. Happy coding!