Create Stunning Images with the Pasha Generator's Cognitive Actions

In this article, we will explore the capabilities of the Pasha Generator by Marceldaczko2, a powerful tool designed for generating images using advanced techniques like inpainting. The Cognitive Actions provided in this spec allow developers to create unique images based on a text prompt and various customizable parameters. Utilizing these pre-built actions can significantly enhance your application’s image generation capabilities, providing flexibility and creative control.
Prerequisites
Before you start integrating the Pasha Generator Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making HTTP requests and handling JSON data.
- Basic knowledge of Python for the conceptual code examples.
Authentication generally involves passing your API key in the request headers to access the Cognitive Actions services.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create an image by blending existing images and utilizing inpainting techniques. You can choose between the 'schnell' model for faster generation or the 'dev' model for more detailed results. This action supports various configurations to enhance image quality and style.
Input
The input for this action is structured as follows:
- prompt (required): A descriptive text prompt for generating the image. For example:
"prompt": "Evil Superman flying upwards through the air, wearing a black Superman suit and the realistic face of an adult man with short dark hair and a beard. He has a serious, intimidating expression, not smiling, and the black Superman logo is visible on his chest. The background features a bright sky and graphic elements referencing FPS games" - mask (optional): Image mask for inpainting mode.
- image (optional): Input image for image-to-image or inpainting mode.
- width (optional): Specifies the width of the generated image (if aspect ratio is set to custom).
- height (optional): Specifies the height of the generated image (if aspect ratio is set to custom).
- numberOfOutputs (optional): Specifies the number of output images to generate.
- imageAspectRatio (optional): Sets the aspect ratio for the generated image.
- imageOutputFormat (optional): Format of the output images (e.g., jpg, png).
- randomSeed (optional): Assigns a seed for reproducible results.
- Additional parameters such as loraScale, guidanceScale, outputQuality, etc., allow for further customization.
Here’s an example input JSON payload:
{
"prompt": "Evil Superman flying upwards through the air, wearing a black Superman suit and the realistic face of an adult man with short dark hair and a beard. He has a serious, intimidating expression, not smiling, and the black Superman logo is visible on his chest. The background features a bright sky and graphic elements referencing FPS games",
"loraScale": 1,
"guidanceScale": 3.5,
"outputQuality": 90,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"imageAspectRatio": "16:9",
"imageOutputFormat": "jpg",
"numberOfInferenceSteps": 28
}
Output
The action typically returns a URL to the generated image. For example:
[
"https://assets.cognitiveactions.com/invocations/1f476486-c264-4a49-9e38-905a1ed708b6/1331720e-c2df-4b4e-8c56-d79b52e7f18e.jpg"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet to demonstrate how you might call the Generate Image with Inpainting action:
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 = "549fc688-0d57-419e-b3ec-9354794b5eb4" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "Evil Superman flying upwards through the air, wearing a black Superman suit and the realistic face of an adult man with short dark hair and a beard. He has a serious, intimidating expression, not smiling, and the black Superman logo is visible on his chest. The background features a bright sky and graphic elements referencing FPS games",
"loraScale": 1,
"guidanceScale": 3.5,
"outputQuality": 90,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"imageAspectRatio": "16:9",
"imageOutputFormat": "jpg",
"numberOfInferenceSteps": 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
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, we replace the action_id with the one for the Generate Image with Inpainting action and structure the JSON payload according to the input schema specified. The endpoint URL and request structure are illustrative and should be adapted based on the actual API.
Conclusion
The Pasha Generator’s Cognitive Actions enable developers to create stunning images through intuitive input parameters and advanced techniques like inpainting. By leveraging these actions, you can enhance your applications with unique and customizable image generation capabilities. Consider exploring additional features and experimenting with different settings to unlock even more creative possibilities. Happy coding!