Elevate Your Applications with Image Generation and Inpainting using sdeviants/ben_20240817

Integrating advanced image generation capabilities into your applications has never been easier with the sdeviants/ben_20240817 Cognitive Actions. This powerful set of actions allows developers to generate AI-enhanced images through sophisticated inpainting and img2img techniques. By leveraging pre-built actions, you can enrich your applications with stunning visuals, streamline workflows, and create unique content tailored to your users' needs.
Prerequisites
Before you start using the Cognitive Actions, make sure you have the following:
- API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform.
- Setup: Familiarity with JSON and making HTTP requests will be beneficial.
Authentication typically involves sending your API key in the request headers, ensuring secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action generates AI-enhanced images using img2img or inpainting modes. This action allows users to specify various inputs—including image dimensions, text prompts, and random seeds—to create refined images. Additional features include applying watermarks and generating multiple images at once.
Input
The action requires a well-structured input object. Below is the schema for the input fields:
- mask: (string, URI) Optional. URI of the input mask for inpaint mode.
- seed: (integer) Optional. Random seed for reproducibility.
- image: (string, URI) Required. URI of the input image.
- width: (integer) Optional. Width of the output image in pixels (default: 1024).
- height: (integer) Optional. Height of the output image in pixels (default: 1024).
- prompt: (string) Required. Textual prompt to guide image generation.
- refine: (string) Optional. Refine style to apply (default: "no_refiner").
- loraScale: (number) Optional. Scale for LoRA adaptation (default: 0.6).
- scheduler: (string) Optional. Type of scheduler (default: "K_EULER").
- guidanceScale: (number) Optional. Scale for classifier-free guidance (default: 7.5).
- applyWatermark: (boolean) Optional. Apply a watermark (default: true).
- negativePrompt: (string) Optional. Textual prompt for aspects to avoid.
- promptStrength: (number) Optional. Influence of the prompt (default: 0.8).
- numberOfOutputs: (integer) Optional. Specify number of output images (default: 1).
- highNoiseFraction: (number) Optional. Fraction of high noise for refinement (default: 0.8).
- numberOfInferenceSteps: (integer) Optional. Number of denoising steps (default: 50).
Example Input
{
"width": 1024,
"height": 1024,
"prompt": "TOK running",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": true,
"negativePrompt": "",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"highNoiseFraction": 0.8,
"numberOfInferenceSteps": 50
}
Output
The action typically returns a URL to the generated image or images.
Example Output
[
"https://assets.cognitiveactions.com/invocations/51309fdb-1e3d-46e4-bec6-f7cd84377719/0a66fa8f-0455-499a-88e5-64f21a1ba402.png"
]
Conceptual Usage Example (Python)
Here’s how you can implement the Generate Image with Inpainting 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 = "b973c52b-0cb7-45f1-8862-72f2f2656606" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "TOK running",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": True,
"negativePrompt": "",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"highNoiseFraction": 0.8,
"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 example, replace the placeholder for your API key and ensure the action ID corresponds to the action you want to execute. The input payload is structured based on the required fields.
Conclusion
The sdeviants/ben_20240817 Cognitive Actions open up a world of possibilities for image creation and manipulation in your applications. By integrating the Generate Image with Inpainting action, you can provide users with unique, AI-enhanced imagery tailored to their requests. Explore these capabilities further and consider how they can enhance your projects, whether for art, design, or any other creative endeavor. Happy coding!