Generate Stunning Images with the imjishan/jishanv2 Cognitive Actions

In the world of image generation, the imjishan/jishanv2 Cognitive Actions provide developers with powerful tools to create detailed images with customizable settings. These actions are designed to streamline the image creation process, allowing for advanced features like inpainting, various output formats, and fine-tuning options. This guide will walk you through the capabilities of the "Generate Custom Image with Mask" action, detailing how to integrate it into your applications seamlessly.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Familiarity with making HTTP requests and handling JSON data.
- Ensure that you can pass the API key in the request headers for authentication.
Cognitive Actions Overview
Generate Custom Image with Mask
The Generate Custom Image with Mask action allows you to create detailed images with the option to use inpainting via masks. This action supports custom dimensions, multiple output formats, and advanced settings such as LoRA intensity for fine-tuning styles and concepts. You can choose between fast and high-quality generation modes depending on your needs.
Input
The input schema for this action requires the following fields:
- prompt (required): A descriptive text guiding the image generation.
- image (optional): A URI of the input image for modifications.
- mask (optional): A URI for the image mask used in inpainting.
- model (optional): Choose between "dev" (default) or "schnell" for inference.
- width (optional): Width of the output image (256-1440 pixels).
- height (optional): Height of the output image (256-1440 pixels).
- goFast (optional): A boolean to enable faster predictions.
- aspectRatio (optional): Select an aspect ratio for the generated image.
- outputFormat (optional): Choose the desired image format (webp, jpg, png).
- numberOfOutputs (optional): Specify how many images to generate (1-4).
- numberOfInferenceSteps (optional): Control the number of denoising steps (1-50).
Example Input:
{
"image": "https://replicate.delivery/pbxt/LbIRPNA6YwIUQxzSjp8WXne60VHPuWTsvn1fIDtg7ldApWFc/out-1.jpg",
"model": "dev",
"prompt": "Jishan stands at the edge of an open sea. He is dressed in dark, blending effortlessly into the serene, muted backdrop. The horizon stretches far behind him, with the calm waters and a pale, overcast sky meeting in the distance. The scene exudes tranquility and introspection, bathed in soft natural light, capturing a peaceful, cinematic moment",
"loraScale": 1,
"aspectRatio": "4:5",
"outputFormat": "jpg",
"guidanceScale": 0.72,
"outputQuality": 100,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"numberOfInferenceSteps": 50
}
Output
The action typically returns a URL to the generated image. The output may vary based on the input parameters provided.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/bc802722-2185-4379-b16f-c10efe3096f8/68ef0cb7-94e7-4a76-a975-77d3dedd0d67.jpg"
]
Conceptual Usage Example (Python)
Here's a conceptual Python snippet demonstrating how to call the Generate Custom Image with Mask 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 = "b99fe2d2-df00-4507-93f3-5b0eac6377d8" # Action ID for Generate Custom Image with Mask
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/LbIRPNA6YwIUQxzSjp8WXne60VHPuWTsvn1fIDtg7ldApWFc/out-1.jpg",
"model": "dev",
"prompt": "Jishan stands at the edge of an open sea. He is dressed in dark, blending effortlessly into the serene, muted backdrop. The horizon stretches far behind him, with the calm waters and a pale, overcast sky meeting in the distance. The scene exudes tranquility and introspection, bathed in soft natural light, capturing a peaceful, cinematic moment",
"loraScale": 1,
"aspectRatio": "4:5",
"outputFormat": "jpg",
"guidanceScale": 0.72,
"outputQuality": 100,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"numberOfInferenceSteps": 50
}
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, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The payload is structured based on the action input requirements, and the response is handled to display either the generated image URL or any errors that may occur.
Conclusion
The imjishan/jishanv2 Cognitive Actions offer a robust way to integrate advanced image generation capabilities into your applications. By utilizing the Generate Custom Image with Mask action, developers can create tailored images, enhancing their applications with stunning visuals. Explore the various parameters to fully leverage the power of this action and consider how this functionality can enrich user experiences in your projects. Happy coding!