Unlocking Creative Potential: Using Image Generation Cognitive Actions

In today's digital landscape, the ability to generate and manipulate images programmatically can open up a realm of creative possibilities. The "chahak-vishvakarma/kamleshvishvakarma2024" Cognitive Actions allow developers to create stunning images through a powerful set of image generation capabilities. These pre-built actions simplify the integration of advanced image generation techniques, such as inpainting and customized model selection, into your applications.
Prerequisites
Before diving into the integration of these Cognitive Actions, ensure you have the following:
- API Key: You will need a valid API key to authenticate your requests. This key will typically be passed in the request headers.
- Internet Access: Since these actions utilize online resources for image processing, a reliable internet connection is required.
Authentication is generally handled by including the API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action creates visually appealing images based on a text prompt, with optional image masking for inpainting. This action is particularly useful for enhancing existing images or generating new ones from descriptive prompts.
- Category: Image Generation
Input
The input schema for this action requires the following fields:
- prompt (required): Descriptive text for image generation.
- mask (optional): URI of the image mask for inpainting.
- image (optional): URI of the input image for inpainting.
- model (optional): Select between "dev" (default) and "schnell" for inference.
- width (optional): Width of the generated image (256 - 1440).
- height (optional): Height of the generated image (256 - 1440).
- guidanceScale (optional): Influences realism in the generated image (0 - 10).
- numberOfOutputs (optional): Number of images to generate (1 - 4).
Example Input JSON:
{
"model": "dev",
"prompt": "chahak-vishvakarma/kamleshvishvakarma2024 is working in a office give a DSLR image",
"guidanceScale": 3.5,
"outputQuality": 90,
"denoisingSteps": 28,
"promptStrength": 0.8,
"loraWeightScale": 1,
"numberOfOutputs": 1,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"additionalLoraWeightScale": 1
}
Output
The action typically returns a URL to the generated image, such as:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/81c3f85a-826d-4ccc-b8e1-f2dfaba74f47/4d164ea7-c744-4162-8653-b4cb3c9e97fe.webp"
]
Conceptual Usage Example (Python)
Here’s how you might implement the action in Python, using the provided input structure:
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 = "fb479ffd-8048-4bbc-ace1-ae7fdea082f8" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "chahak-vishvakarma/kamleshvishvakarma2024 is working in a office give a DSLR image",
"guidanceScale": 3.5,
"outputQuality": 90,
"denoisingSteps": 28,
"promptStrength": 0.8,
"loraWeightScale": 1,
"numberOfOutputs": 1,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"additionalLoraWeightScale": 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 the placeholders with your actual API key and ensure the action ID corresponds to the desired action. The payload is structured to meet the action's input requirements, aiding in generating impressive images.
Conclusion
The Generate Image with Inpainting action from the "chahak-vishvakarma/kamleshvishvakarma2024" Cognitive Actions suite enables developers to harness the power of AI-generated imagery effortlessly. By integrating this action into your applications, you can create unique visual content tailored to your needs. Whether for artistic projects, marketing materials, or enhancing user interfaces, the potential applications are vast. Start exploring these capabilities today and unlock your creative potential!