Enhance Your Applications with Image Inpainting using leoastro21/asa-lipstick Cognitive Actions

In the realm of image processing, the ability to generate and manipulate images on-the-fly is a powerful feature for developers. The leoastro21/asa-lipstick Cognitive Actions provide a robust solution for creating inpainted images, allowing for customization through various parameters. By leveraging these pre-built actions, developers can enhance their applications with advanced image generation capabilities without delving into the complexities of model training and image processing algorithms.
Prerequisites
Before you dive into using the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic knowledge of JSON and HTTP requests.
Authentication typically involves passing your API key in the request headers, which allows you to access the Cognitive Actions you wish to integrate into your application.
Cognitive Actions Overview
Generate Inpainted Image
Description:
This action creates an inpainted image by utilizing either the 'dev' or 'schnell' model based on the provided configuration. It supports customizable aspect ratios, prompt strength, and various output formats, with options for accelerated generation processes.
Category: Image Processing
Input
The input schema for this action is structured as follows:
{
"prompt": "string (required)",
"mask": "string (optional, uri)",
"seed": "integer (optional)",
"image": "string (optional, uri)",
"model": "string (default: 'dev', options: ['dev', 'schnell'])",
"goFast": "boolean (default: false)",
"width": "integer (optional, range: 256-1440)",
"height": "integer (optional, range: 256-1440)",
"loraMultiplier": "number (default: 1, range: -1 to 3)",
"imageMegapixels": "string (default: '1', options: ['1', '0.25'])",
"numberOfOutputs": "integer (default: 1, range: 1-4)",
"imageAspectRatio": "string (default: '1:1', options: ['1:1', '16:9', '21:9', '3:2', '2:3', '4:5', '5:4', '3:4', '4:3', '9:16', '9:21', 'custom'])",
"imageOutputFormat": "string (default: 'webp', options: ['webp', 'jpg', 'png'])",
"imageOutputQuality": "integer (default: 80, range: 0-100)",
"imagePromptStrength": "number (default: 0.8, range: 0-1)",
"turnOffSafetyChecker": "boolean (default: false)",
"additionalWeights": "string (optional)",
"additionalLoraWeights": "string (optional)",
"diffusionGuidanceScale": "number (default: 3, range: 0-10)",
"numberOfInferenceSteps": "integer (default: 28, range: 1-50)",
"additionalLoraMultiplier": "number (default: 1, range: -1 to 3)"
}
Example Input:
{
"model": "dev",
"goFast": false,
"prompt": "ASALIPSTICK 3 female models, enjoying picnic, basking in sun, cinematic, all wearing lipstick",
"loraMultiplier": 1,
"imageMegapixels": "1",
"numberOfOutputs": 1,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"imagePromptStrength": 0.8,
"diffusionGuidanceScale": 3,
"numberOfInferenceSteps": 28,
"additionalLoraMultiplier": 1
}
Output
The action typically returns an array of URLs pointing to the generated images. Here’s an example of the output:
[
"https://assets.cognitiveactions.com/invocations/592deca5-5fc4-4122-b458-e39e2dcc0ec2/5b244d31-1b23-49e5-9288-e613929edd31.webp"
]
Conceptual Usage Example (Python)
Here’s how you could call the Generate Inpainted Image 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 = "74cb2ca5-f1e9-438a-ab3c-020852698528" # Action ID for Generate Inpainted Image
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"prompt": "ASALIPSTICK 3 female models, enjoying picnic, basking in sun, cinematic, all wearing lipstick",
"loraMultiplier": 1,
"imageMegapixels": "1",
"numberOfOutputs": 1,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"imagePromptStrength": 0.8,
"diffusionGuidanceScale": 3,
"numberOfInferenceSteps": 28,
"additionalLoraMultiplier": 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 snippet, replace the COGNITIVE_ACTIONS_API_KEY and the execution URL with your actual values. The example demonstrates how to structure the input JSON payload based on the action's requirements.
Conclusion
The Generate Inpainted Image action from the leoastro21/asa-lipstick Cognitive Actions offers a flexible and powerful way to create images tailored to specific needs. By utilizing the various parameters available, developers can create unique, high-quality images that enhance their applications.
Explore these capabilities and consider how they can be integrated into your projects to deliver engaging and visually appealing content!