Enhance Your Applications with Image Generation Using princezoho/gunslingers-training-2 Actions

In today's fast-paced digital landscape, integrating advanced image generation capabilities can significantly enhance your applications. The princezoho/gunslingers-training-2 spec provides powerful Cognitive Actions that enable developers to create stunning images through innovative techniques like inpainting. These pre-built actions streamline the development process, allowing you to focus on creativity while harnessing the power of AI.
Prerequisites
Before diving in, ensure you have access to the Cognitive Actions platform and obtain your API key. This key will be used to authenticate your requests by passing it in the headers of your API calls.
Cognitive Actions Overview
Generate Image with Inpainting
Purpose
The Generate Image with Inpainting action allows you to generate images by utilizing inpainting techniques. This action supports features such as prompt input, guidance scales, and refinement styles. By specifying a mask, you can preserve or alter certain parts of an image, ensuring high-quality output through advanced schedulers and classifiers.
Input
The required input fields for this action include:
- mask (string): URI of the mask image for inpaint mode. Black areas are preserved, white areas are altered.
- image (string): URI of the input image for img2img or inpaint modes.
- width (integer): Width of the generated output image in pixels (default is 1024).
- height (integer): Height of the generated output image in pixels (default is 1024).
- prompt (string): Text prompt specifying the image content and style.
- numberOfOutputs (integer): Number of images to generate (1 to 4).
- numInferenceSteps (integer): Total number of denoising steps (1 to 500).
- guidanceScale (number): Strength of classifier-free guidance (1 to 50).
- promptStrength (number): Intensity of how much the input prompt impacts the generation (0 to 1).
Here is a practical example of the JSON payload needed to invoke this action:
{
"width": 1920,
"height": 1080,
"prompt": "In the style of SLINGERBG Mountain Pass through mountain ranges, inverted colors",
"refine": "no_refiner",
"scheduler": "K_EULER",
"addWatermark": true,
"loraStrength": 0.83,
"guidanceScale": 7.5,
"negativePrompt": "human, people, horse",
"promptStrength": 0.8,
"numberOfOutputs": 4,
"highNoiseFraction": 0.8,
"numInferenceSteps": 50
}
Output
The action typically returns an array of URLs pointing to the generated images. Here’s an example of the output you might receive:
[
"https://assets.cognitiveactions.com/invocations/8be11d85-dc9e-4673-af3f-aaac5f71a60c/37689861-c0dc-4f95-aae0-b6fd181a3bc5.png",
"https://assets.cognitiveactions.com/invocations/8be11d85-dc9e-4673-af3f-aaac5f71a60c/81ab2b31-e0ba-4bf9-9f19-5d1aee3c2f9a.png",
"https://assets.cognitiveactions.com/invocations/8be11d85-dc9e-4673-af3f-aaac5f71a60c/b458b79b-721a-4052-a869-796fcc68c47c.png",
"https://assets.cognitiveactions.com/invocations/8be11d85-dc9e-4673-af3f-aaac5f71a60c/c1baa6d9-01e1-4cbe-89f8-4cdfb6e8aca2.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the Generate Image with Inpainting action using 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 = "c215e133-3ab4-48a3-9869-450a2dad2358" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"width": 1920,
"height": 1080,
"prompt": "In the style of SLINGERBG Mountain Pass through mountain ranges, inverted colors",
"refine": "no_refiner",
"scheduler": "K_EULER",
"addWatermark": True,
"loraStrength": 0.83,
"guidanceScale": 7.5,
"negativePrompt": "human, people, horse",
"promptStrength": 0.8,
"numberOfOutputs": 4,
"highNoiseFraction": 0.8,
"numInferenceSteps": 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_KEYwith your actual API key. - The
action_idcorresponds to the Generate Image with Inpainting action. - The
payloadis structured based on the required and optional fields for this action.
Conclusion
Integrating the princezoho/gunslingers-training-2 Cognitive Actions into your applications opens up exciting possibilities for image creation and manipulation. By utilizing the Generate Image with Inpainting action, you can enhance user experiences and bring your creative visions to life. Whether you're building a content creation tool or an art application, these actions provide a robust foundation for your projects. Start experimenting with these capabilities today and unlock the potential of AI-driven image generation!