Unleash Creativity: Image Generation with uxspider/rayban Cognitive Actions

In the age of digital content creation, generating unique images tailored to specific prompts can significantly enhance user engagement and creativity. The uxspider/rayban API offers a powerful Cognitive Action that leverages inpainting techniques to generate stunning images based on user-defined criteria. By utilizing this pre-built action, developers can easily integrate sophisticated image generation capabilities into their applications, allowing for personalized content creation that captures attention.
Prerequisites
Before you can start using the Cognitive Actions, ensure that you have an API key for the uxspider/rayban platform. This key will be required for authentication when making requests to the Cognitive Actions endpoint. Typically, authentication is done by including the API key in the request headers.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action creates images based on specific prompts and optional masks. This action supports two models—dev for detailed outputs and schnell for faster generation—allowing developers to choose the best fit for their needs.
Input
The input for this action requires a JSON object with the following schema:
- prompt (string, required): The detailed description of the image to be generated.
- mask (string, optional): A URI for the image mask to guide the inpainting process.
- seed (integer, optional): A random seed to ensure reproducibility.
- image (string, optional): Input image for image-to-image generation.
- model (string, optional): Selects the inference model (
devorschnell). - width (integer, optional): Width of the generated image.
- height (integer, optional): Height of the generated image.
- aspectRatio (string, optional): Specifies the aspect ratio.
- outputFormat (string, optional): Desired format of the output image (e.g.,
webp,jpg,png). - numOutputs (integer, optional): Number of images to generate.
- guidanceScale (number, optional): Scale for the guidance during image generation.
- outputQuality (integer, optional): Quality level for the output image.
Here's an example of a JSON payload that can be used to invoke this action:
{
"model": "dev",
"prompt": "High-end fashion photoshoot with lens focusing on sunglasses resting on a sleek white marble surface. Around the sunglasses, there are scattered Sicilian lemons, with a serene pool view as the backdrop.",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "2:3",
"outputFormat": "png",
"guidanceScale": 2.77,
"outputQuality": 100,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numInferenceSteps": 26
}
Output
Upon successful execution, this action returns an array of image URLs that link to the generated images. For example:
[
"https://assets.cognitiveactions.com/invocations/5688a769-9a79-463b-9db3-33e7a87d44ab/f1d673a8-29ce-470b-9ca1-0fb41f3564e7.png"
]
Conceptual Usage Example (Python)
Here's a conceptual Python code snippet demonstrating how to call this Cognitive 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 = "e6f206e1-d796-41e1-b7e7-8d905a9629dd" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "High-end fashion photoshoot with lens focusing on sunglasses resting on a sleek white marble surface. Around the sunglasses, there are scattered Sicilian lemons, with a serene pool view as the backdrop.",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "2:3",
"outputFormat": "png",
"guidanceScale": 2.77,
"outputQuality": 100,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numInferenceSteps": 26
}
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}
)
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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured to match the requirements of the Generate Image with Inpainting action. This code assumes a hypothetical endpoint and request structure.
Conclusion
The uxspider/rayban Cognitive Action for image generation using inpainting techniques provides developers with a robust tool to create custom images tailored to their application's needs. By leveraging this action, you can enhance user engagement through visually appealing content. Explore further use cases, experiment with model configurations, and unlock the full potential of your applications with advanced image generation capabilities!