Generate Stunning Images with Cognitive Actions for vespo300/mar24

In the world of artificial intelligence and machine learning, visual content generation is becoming increasingly important. The vespo300/mar24 API offers a powerful set of Cognitive Actions, specifically designed for image generation through image-to-image translation. These pre-built actions allow developers to create customized images with various attributes, making it easier to integrate image generation capabilities into their applications.
This blog post will guide you through the available Cognitive Actions in the vespo300/mar24 spec, helping you understand their capabilities and how to effectively utilize them in your projects.
Prerequisites
To get started with Cognitive Actions, you will need an API key for the Cognitive Actions platform. Once you have your API key, you can include it in the headers of your API requests for authentication. This allows you to securely access the image generation features provided by the API.
Cognitive Actions Overview
Generate Image with Image-to-Image Translation
The Generate Image with Image-to-Image Translation action allows you to create images using a provided text prompt along with options for inpainting and customization of various image attributes. You can choose between different inference models for optimal results or efficiency, and even control the generation process with advanced settings.
Input
The required and optional parameters for this action are defined in the input schema as follows:
- prompt: (string, required) A text prompt for generating the image. Specifying a 'trigger_word' can enhance object activation.
- imageMask: (string, optional) URI of the image mask for inpainting mode.
- modelType: (string, optional) Selects the inference model; options are
devorschnell. - imageWidth: (integer, optional) Specifies the width of the generated image.
- inputImage: (string, optional) URI of the input image for image-to-image or inpainting mode.
- randomSeed: (integer, optional) Sets a random seed for reproducible generation.
- imageHeight: (integer, optional) Specifies the height of the generated image.
- outputCount: (integer, optional) The number of images to generate (1 to 4).
- customWeights: (string, optional) Load custom LoRA weights.
- loraIntensity: (number, optional) Adjusts the intensity of the main LoRA application.
- enableFastMode: (boolean, optional) Enables fast generation mode.
- imageResolution: (string, optional) Sets the image resolution in megapixels.
- promptIntensity: (number, optional) Controls the intensity of the prompt in image-to-image generation.
- imageAspectRatio: (string, optional) Sets the aspect ratio for the generated image.
- imageOutputFormat: (string, optional) Selects the file format for the output images (webp, jpg, png).
- imageOutputQuality: (integer, optional) Specifies the quality level for output images.
- inferenceStepCount: (integer, optional) Determines the number of denoising steps.
- diffusionGuidanceScale: (number, optional) Sets the guidance scale for the diffusion process.
- disableImageSafetyChecker: (boolean, optional) Option to disable the safety checker for generated images.
Example Input
Here’s an example of the JSON payload required for this action:
{
"prompt": "Tomkar an African American male is running down a street in New York City at night.",
"modelType": "dev",
"inputImage": "https://replicate.delivery/pbxt/M6Us8Hd2r3kqlXO1gjWmBfG4fLvXS10cCCPD9VbckBL1QnPJ/IMG_2109.jpeg",
"outputCount": 2,
"loraIntensity": 1,
"enableFastMode": false,
"imageResolution": "1",
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"inferenceStepCount": 30,
"diffusionGuidanceScale": 3
}
Output
The action typically returns a list of generated image URLs. For example:
[
"https://assets.cognitiveactions.com/invocations/bf53f66e-2a68-42bb-a627-25397d82cb72/4615d2f7-6b68-4ae4-9886-03f5ec1f6682.webp",
"https://assets.cognitiveactions.com/invocations/bf53f66e-2a68-42bb-a627-25397d82cb72/f8edf71b-d543-4dd0-a2e5-8b54472bc54b.webp"
]
Conceptual Usage Example (Python)
Here is a conceptual example of how to use this 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 = "f9247c1b-9a4d-45e1-a500-a5aa74e6f2d6" # Action ID for Generate Image with Image-to-Image Translation
# Construct the input payload based on the action's requirements
payload = {
"prompt": "Tomkar an African American male is running down a street in New York City at night.",
"modelType": "dev",
"inputImage": "https://replicate.delivery/pbxt/M6Us8Hd2r3kqlXO1gjWmBfG4fLvXS10cCCPD9VbckBL1QnPJ/IMG_2109.jpeg",
"outputCount": 2,
"loraIntensity": 1,
"enableFastMode": False,
"imageResolution": "1",
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"inferenceStepCount": 30,
"diffusionGuidanceScale": 3
}
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 Python snippet, you should replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload constructed includes all parameters needed for the image generation request.
Conclusion
The Generate Image with Image-to-Image Translation action in the vespo300/mar24 API offers powerful capabilities for developers looking to create customized images. With a variety of input options and advanced settings, you can tailor the image generation process to suit your needs.
Next steps could include experimenting with different parameters to see how they affect the generated images or integrating this functionality into a larger application that requires dynamic image creation. Happy coding!