Automate Image Generation with Cognitive Actions from ianochiengai/vinci

In the world of artificial intelligence, the ability to generate images based on textual prompts is a game changer. The ianochiengai/vinci Cognitive Actions provide developers with powerful tools for image generation, including advanced techniques like image inpainting and image-to-image transformations. These pre-built actions allow for detailed control over various aspects of the generated images, making them ideal for a range of applications from artistic creation to product design.
Prerequisites
To get started with the Cognitive Actions from ianochiengai/vinci, you'll need an API key for authentication. This key should be passed in the headers of your requests to ensure secure access.
Here’s a conceptual overview of how authentication might work:
- API Key: Include the API key in the request headers as follows:
{ "Authorization": "Bearer YOUR_COGNITIVE_ACTIONS_API_KEY", "Content-Type": "application/json" }
Cognitive Actions Overview
Generate Image with Image Inpainting
Description:
This operation generates images using image-to-image or inpainting techniques. It allows detailed control over aspects such as mask, seed, height, width, aspect ratio, and model selection. The operation supports advanced parameters like LoRA intensity, guidance scale, and fast mode for quick predictions, optimizing both speed and quality.
Category: image-generation
Input:
The required fields for this action include:
- prompt (string): Text prompt to guide the image generation process.
- goFast (boolean): Execute predictions with a speed-optimized model (default: false).
- aspectRatio (string): Defines the aspect ratio of the generated image (default: "1:1").
- numOutputs (integer): Determines how many images will be generated per request (default: 1).
- outputFormat (string): Selects the desired image file format for output (default: "webp").
- guidanceScale (number): Influences the guided diffusion process (default: 3).
- outputQuality (integer): Specifies JPEG quality of saved output images (default: 80).
- loraScale (number): Strength of the main LoRA application (default: 1).
- promptStrength (number): Controls the influence of the prompt during transformations (default: 0.8).
- Additional parameters such as image, mask, seed, height, width, and others allow for further customization.
Example Input:
{
"goFast": false,
"prompt": "A realistic black-and-white portrait of Vinci, wearing a classic black turtleneck and round glasses...",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "jpg",
"guidanceScale": 3,
"outputQuality": 80,
"promptStrength": 0.8,
"numInferenceSteps": 28
}
Output:
The action typically returns a list of URLs pointing to the generated images.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/2baecf38-0445-4a7d-89a8-fb509dc94e32/4dca93bf-2852-415f-9bad-ba830d6a0008.jpg"
]
Conceptual Usage Example (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 = "1667dd72-0b48-4ec1-8a3b-ae99c6a2d16e" # Action ID for Generate Image with Image Inpainting
# Construct the input payload based on the action's requirements
payload = {
"goFast": false,
"prompt": "A realistic black-and-white portrait of Vinci, wearing a classic black turtleneck and round glasses...",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "jpg",
"guidanceScale": 3,
"outputQuality": 80,
"promptStrength": 0.8,
"numInferenceSteps": 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 example, the action ID and input payload are structured to match the requirements. Adjust the endpoint URL and request structure as necessary to fit your specific implementation.
Conclusion
The ianochiengai/vinci Cognitive Actions empower developers to create stunning images through intuitive and flexible parameters. Whether you are looking to generate unique artwork, enhance product visuals, or develop creative applications, these actions provide the tools you need. Explore the possibilities and consider integrating these capabilities into your projects for a more dynamic user experience!