Generate Stunning Images with ShapeStudio's Cognitive Actions

In the realm of image generation, ShapeStudio's Cognitive Actions provide powerful tools for developers to create high-quality images through advanced techniques like inpainting and image-to-image transformation. These pre-built actions allow you to harness sophisticated models and configurations, ensuring detailed and customizable outputs tailored to your application’s needs.
Prerequisites
Before you start integrating ShapeStudio's Cognitive Actions into your projects, ensure you have:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Familiarity with JSON data structures to construct input payloads.
- Basic knowledge of making HTTP requests, as you’ll be sending your inputs to a specific endpoint (to be determined based on your service setup).
Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the cognitive actions.
Cognitive Actions Overview
Generate Images with Inpainting
Description: This action allows you to generate high-quality images using image-to-image transformation and inpainting techniques. It's designed to support various models and configurations for aspect ratio, resolution, and speed optimization, ensuring detailed and customizable image outputs.
Category: Image Generation
Input
The input schema for this action requires the following fields:
- prompt (required): A descriptive text prompt for generating the image.
- model (optional): The model to use for inference (default:
dev). - goFast (optional): Enable faster predictions (default:
false). - imageAspectRatio (optional): Aspect ratio for the generated image (default:
1:1). - imageOutputFormat (optional): Format of the output images (default:
webp). - numberOfOutputs (optional): Number of outputs to generate (default:
1). - guidanceScale (optional): Guidance scale for the diffusion process (default:
3). - inferenceStepsCount (optional): Number of denoising steps (default:
28). - Additional parameters control various aspects of image generation and quality.
Example Input:
{
"model": "dev",
"goFast": false,
"prompt": "BOOK TOK on the wooden table, top-down",
"megapixels": "1",
"guidanceScale": 3,
"mainLoraScale": 1,
"numberOfOutputs": 1,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"inferenceStepsCount": 28
}
Output
After executing this action, you can expect a response that typically includes URLs to the generated images. Here’s an example of a successful output:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/50e3446d-8303-4c25-8b7c-66a39d1f342c/cb48722d-c15f-4dcb-98fa-74b17cf8b966.webp"
]
Conceptual Usage Example (Python)
Here’s how you might call the Generate Images with Inpainting action in 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 = "b7900a46-e136-4206-b1cc-7d728917d989" # Action ID for Generate Images with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"prompt": "BOOK TOK on the wooden table, top-down",
"megapixels": "1",
"guidanceScale": 3,
"mainLoraScale": 1,
"numberOfOutputs": 1,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"inferenceStepsCount": 28
}
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 can see how to set up the input payload and send it to the hypothetical Cognitive Actions endpoint. The action_id corresponds to the specific action you want to execute, and the payload is structured according to the schema detailed above.
Conclusion
Integrating ShapeStudio's Cognitive Actions into your applications opens up a world of possibilities for generating stunning images tailored to your specifications. With the ability to customize model configurations, aspect ratios, and output formats, developers can create unique visual content efficiently. Explore further and experiment with different parameters to truly harness the power of image generation in your projects!