Create Stunning Images with jbilcke/sdxl-starfield Cognitive Actions

In the realm of image generation, the jbilcke/sdxl-starfield Cognitive Actions offer developers a powerful toolkit to create and manipulate images using the SDXL Starfield model. With elegant features like inpainting, customizable prompts, and various refinement strategies, these pre-built actions enable seamless integration into applications aimed at delivering visually captivating content. Whether you’re generating imaginative scenes or refining existing images, these actions streamline the creative process.
Prerequisites
To get started with the Cognitive Actions, you will need:
- An API key for the Cognitive Actions platform, which will authenticate your requests.
- Basic familiarity with JSON formatting for structuring input and output data.
Authentication typically involves passing your API key in the request headers. Conceptually, this can look like:
Authorization: Bearer YOUR_COGNITIVE_ACTIONS_API_KEY
Cognitive Actions Overview
Generate Image with Starfield Inpaint
The Generate Image with Starfield Inpaint action enables developers to generate images using the SDXL Starfield model, featuring capabilities like inpainting, refinement styles, and customizable prompts. This action is categorized under image-generation.
Input
The input for this action requires a structured JSON object with various properties:
- mask (string, optional): Input mask for inpaint mode. Black areas are preserved, and white areas are inpainted.
- seed (integer, optional): Random seed for image generation. Leave blank to use a randomized seed.
- image (string, optional): Input image for use in img2img or inpaint mode.
- width (integer, optional): Specifies the width of the output image in pixels (default: 1024).
- height (integer, optional): Specifies the height of the output image in pixels (default: 1024).
- prompt (string, required): Descriptive prompt for generating the image (default: "An astronaut riding a rainbow unicorn").
- loraScale (number, optional): LoRA additive scale (default: 0.6, range: 0-1).
- numOutputs (integer, optional): Number of images to generate (default: 1, range: 1-4).
- loraWeights (string, optional): Specifies the LoRA weights to use.
- refineSteps (integer, optional): Number of refinement steps for base_image_refiner.
- guidanceScale (number, optional): Scale factor for classifier-free guidance (default: 7.5, range: 1-50).
- highNoiseFrac (number, optional): Specifies the fraction of noise to apply (default: 0.8, range: 0-1).
- schedulerType (string, optional): Specifies the scheduling algorithm (default: "K_EULER").
- applyWatermark (boolean, optional): Applies a watermark to the image (default: true).
- negativePrompt (string, optional): Attributes to avoid during image generation.
- promptStrength (number, optional): Determines prompt influence strength (default: 0.8, range: 0-1).
- refineStrategy (string, optional): Style of image refinement (default: "no_refiner").
- numInferenceSteps (integer, optional): Number of denoising steps (default: 50, range: 1-500).
- disableSafetyChecker (boolean, optional): Disable the safety checker for generated images (default: false).
Example Input:
{
"width": 1024,
"height": 768,
"prompt": "japanese garden, beautiful, zen garden, skyline, neotokyo, sci-fi, in the style of TOK",
"loraScale": 0.9,
"numOutputs": 1,
"guidanceScale": 7.5,
"highNoiseFrac": 0.8,
"schedulerType": "K_EULER",
"applyWatermark": true,
"negativePrompt": "photo, drawing, cropped",
"promptStrength": 0.8,
"refineStrategy": "expert_ensemble_refiner",
"numInferenceSteps": 90
}
Output
The output of the action typically returns an array of URLs pointing to the generated images. For example:
[
"https://assets.cognitiveactions.com/invocations/f861496f-21d4-454d-bd1b-61aa51d44320/050229a4-ecba-4b26-b11e-dbe2d0e75fda.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how to call this 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 = "dc8fb9f9-a9fc-4cc1-ad0e-e440b4c742cc" # Action ID for Generate Image with Starfield Inpaint
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 768,
"prompt": "japanese garden, beautiful, zen garden, skyline, neotokyo, sci-fi, in the style of TOK",
"loraScale": 0.9,
"numOutputs": 1,
"guidanceScale": 7.5,
"highNoiseFrac": 0.8,
"schedulerType": "K_EULER",
"applyWatermark": True,
"negativePrompt": "photo, drawing, cropped",
"promptStrength": 0.8,
"refineStrategy": "expert_ensemble_refiner",
"numInferenceSteps": 90
}
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 snippet, replace the COGNITIVE_ACTIONS_API_KEY with your actual API key and utilize the payload structure as specified for the input. The endpoint URL and request structure are illustrative and may vary based on the implementation.
Conclusion
The jbilcke/sdxl-starfield Cognitive Actions provide a robust framework for generating and refining images with ease. By leveraging the various parameters and options available, developers can create visually stunning images tailored to their applications. As you integrate these actions into your projects, consider exploring different prompts and settings to fully harness the power of image generation. Happy coding!