Generate Stunning Images with Cognitive Actions from leticiaaduke/test2

Cognitive Actions from the spec leticiaaduke/test2 provide developers with powerful tools for generating high-quality images using advanced inpainting techniques. These pre-built actions simplify the integration of image generation capabilities into applications, enabling developers to create visually appealing content quickly and efficiently. With customizable parameters, users can control the output to meet their specific needs, whether for creative projects or professional use.
Prerequisites
Before diving into the integration of Cognitive Actions, ensure you have an API key for the Cognitive Actions platform. Typically, authentication is handled by including this API key in the request headers, allowing you to securely access the available actions.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create high-quality images by utilizing inpainting techniques. You can select between two models: dev, which is optimized for detailed outputs, and schnell, designed for faster results. This action is categorized under image-generation.
Input
The input for this action requires a prompt and supports various optional fields. Here’s a breakdown of the input schema and an example:
{
"prompt": "A confident woman le with pale skin and long, sleek brown shoulder length hair sitting on a chair. She is dressed in a perfectly fit tailored deep teal suit with satin lapels, paired with a black top underneath. The background is softly textured, creating a subtle contrast with her polished and elegant appearance. Her expression is poised and composed, exuding authority and charisma. The shot is professional. She has dark eyes.",
"image": "https://replicate.delivery/pbxt/M8wxklFIjIjicmWCvhCJ3dsNPV9Nt7sdz6TkeMz7DoZUAasS/IMG_0954.png",
"model": "dev",
"megapixels": "1",
"imageFormat": "png",
"outputCount": 4,
"imageQuality": 100,
"loraIntensity": 1,
"denoisingSteps": 45,
"promptStrength": 0.9,
"acceleratedMode": false,
"processGuidance": 2,
"imageAspectRatio": "1:1",
"additionalLoraIntensity": 1
}
- Required Field:
prompt: Describes the image to be generated.
- Optional Fields:
image: Input image for inpainting mode.model: Choose between "dev" and "schnell".megapixels,imageFormat,outputCount,imageQuality, among others, allow for further customization.
Output
The action returns an array of URLs pointing to the generated images. Here’s an example of the output you can expect:
[
"https://assets.cognitiveactions.com/invocations/e78f9458-c1c5-412b-bfc9-910834e89415/e1b02ef7-3515-4f2c-b9f6-872186d800c7.png",
"https://assets.cognitiveactions.com/invocations/e78f9458-c1c5-412b-bfc9-910834e89415/7ffbb0b2-28ed-4dc9-8a3d-a019248db0d1.png",
"https://assets.cognitiveactions.com/invocations/e78f9458-c1c5-412b-bfc9-910834e89415/47e8a9e5-596d-43c2-a2dc-ad0482304011.png",
"https://assets.cognitiveactions.com/invocations/e78f9458-c1c5-412b-bfc9-910834e89415/9339e8f7-87ba-4296-95d4-e2d4d92bdfcc.png"
]
Conceptual Usage Example (Python)
Below is a conceptual example of how you might call this Cognitive 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 = "730e1de9-ab44-4c49-b5be-1475346f09ca" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "A confident woman le with pale skin and long, sleek brown shoulder length hair sitting on a chair. She is dressed in a perfectly fit tailored deep teal suit with satin lapels, paired with a black top underneath. The background is softly textured, creating a subtle contrast with her polished and elegant appearance. Her expression is poised and composed, exuding authority and charisma. The shot is professional. She has dark eyes.",
"image": "https://replicate.delivery/pbxt/M8wxklFIjIjicmWCvhCJ3dsNPV9Nt7sdz6TkeMz7DoZUAasS/IMG_0954.png",
"model": "dev",
"megapixels": "1",
"imageFormat": "png",
"outputCount": 4,
"imageQuality": 100,
"loraIntensity": 1,
"denoisingSteps": 45,
"promptStrength": 0.9,
"acceleratedMode": False,
"processGuidance": 2,
"imageAspectRatio": "1:1",
"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, you set up the API key and endpoint, create a payload that adheres to the input schema, and execute the action by making a POST request. The structure of the input and output as specified in the payload and response handling is straightforward.
Conclusion
The Generate Image with Inpainting action from the leticiaaduke/test2 spec empowers developers to easily create high-quality images tailored to specific needs. This action, with its customizable parameters, opens up numerous possibilities for applications ranging from content generation to artistic expression. As you explore these capabilities, consider experimenting with different parameters to achieve the best results for your projects. Happy coding!