Enhance Your Applications with Image Generation Using Lumiva Glasses Cognitive Actions

In the rapidly evolving world of artificial intelligence, image generation has become a key area of interest for developers looking to enhance their applications. The Lumiva Glasses Cognitive Actions provide developers with powerful tools to generate images using advanced inpainting techniques. This API allows for various customization options, enabling the creation of high-quality visuals tailored to specific needs. Let's explore how you can integrate these actions into your applications.
Prerequisites
Before you begin using the Lumiva Glasses Cognitive Actions, ensure you meet the following requirements:
- An API key for the Lumiva Cognitive Actions platform.
- Familiarity with making API calls and handling JSON data.
To authenticate your requests, you will typically pass your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows developers to create images using an inpainting model. This action supports various customization options, including image masks, aspect ratios, and model preferences for inference speed.
Input
The action requires a JSON object as input, with the following schema:
{
"prompt": "string (required)",
"mask": "string (optional, uri)",
"image": "string (optional, uri)",
"model": "string (default: 'dev')",
"width": "integer (optional, 256-1440)",
"height": "integer (optional, 256-1440)",
"megapixels": "string (default: '1')",
"imageFormat": "string (default: 'webp')",
"outputCount": "integer (default: 1, 1-4)",
"imageQuality": "integer (default: 80, 0-100)",
"seed": "integer (optional)",
"imageAspectRatio": "string (default: '1:1')",
"enableSpeedMode": "boolean (default: false)",
"additionalLoraWeights": "string (optional)",
"mainLoraIntensity": "number (default: 1)",
"additionalLoraIntensity": "number (default: 1)",
"inferenceStepCount": "integer (default: 28, 1-50)",
"safetyCheckerDisabled": "boolean (default: false)",
"promptIntensity": "number (default: 0.8, 0-1)",
"guidanceIntensity": "number (default: 3, 0-10)"
}
Example Input:
{
"model": "dev",
"prompt": "LUMIVAGLASSES in front of a ski and snowboard with mountain background, high quality, product photoshop",
"imageFormat": "png",
"outputCount": 1,
"imageQuality": 80,
"promptIntensity": 0.8,
"imageAspectRatio": "4:5",
"guidanceIntensity": 3.5,
"mainLoraIntensity": 1,
"inferenceStepCount": 28,
"additionalLoraIntensity": 1
}
Output
The action typically returns a JSON array containing URLs of the generated images. An example output would look like this:
[
"https://assets.cognitiveactions.com/invocations/e2ec0bc5-fce0-4444-a092-e82d1cae4ec8/2ce5ba96-4a5d-4d90-9a14-914dbcef02ba.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how you might call the Generate Image with 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 = "d73800d8-2322-4f23-86ee-138e228e98f2" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "LUMIVAGLASSES in front of a ski and snowboard with mountain background, high quality, product photoshop",
"imageFormat": "png",
"outputCount": 1,
"imageQuality": 80,
"promptIntensity": 0.8,
"imageAspectRatio": "4:5",
"guidanceIntensity": 3.5,
"mainLoraIntensity": 1,
"inferenceStepCount": 28,
"additionalLoraIntensity": 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_KEYwith your actual API key. - The
action_idis set to the ID for the Generate Image with Inpainting action. - The
payloadis constructed according to the required input schema. - The API call is made using
requests.post, and the response is handled accordingly.
Conclusion
The Lumiva Glasses Cognitive Actions, particularly the Generate Image with Inpainting action, offer developers powerful capabilities for image synthesis and customization. By integrating these actions into your applications, you can create high-quality, tailored visuals that enhance user experiences. Consider exploring more use cases, such as generating unique marketing images or enhancing visual content for your projects. Happy coding!