Generate and Edit Images with Reliberate v3: A Developer's Guide

In today’s digital landscape, the demand for engaging and high-quality images is paramount. The Reliberate v3 API offers developers powerful Cognitive Actions specifically designed for generating and editing images. With functionalities like Text-to-Image, Image-to-Image, and Inpainting, these pre-built actions facilitate precise control over image attributes through customizable prompts. In this blog post, we'll explore how to effectively integrate the Reliberate v3 Cognitive Actions into your applications.
Prerequisites
Before you start using the Reliberate v3 Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- A basic understanding of JSON structure, as the input and output formats use JSON.
- Familiarity with making HTTP requests in your preferred programming language, particularly Python for our examples.
To authenticate, you will typically pass your API key in the request headers, allowing secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate and Edit Images with Reliberate v3
Purpose:
This action leverages the Reliberate v3 model to generate and edit images. It supports various modes, including Text-to-Image, Image-to-Image, and Inpainting, enabling developers to create highly customized visuals based on detailed textual prompts.
Category:
Image Generation
Input: The input schema consists of several fields, allowing extensive customization. Here’s a breakdown of the required and optional fields:
- mask (optional): URI of the mask image for inpainting.
- seed (optional): Integer seed for random number generation (default: random).
- image (optional): URI of the input image for img2img and inpainting modes.
- width (optional): Width of the output image in pixels (default: 512, max: 1920).
- height (optional): Height of the output image in pixels (default: 728, max: 1920).
- prompt (required): Descriptive text for desired image attributes (default: "a photo of a redhead girl...").
- strength (optional): Transformation weight (default: 1, range: 0-1).
- guidanceScale (optional): Scale for prompt adherence (default: 7.5, range: 0-10).
- schedulerType (optional): Type of scheduler for image generation (default: "Euler A Karras").
- negativePrompt (optional): Describes undesirable attributes (default: "deformed, disfigured...").
- numberOfOutputs (optional): Number of images to generate (default: 1, range: 1-4).
- numberOfInferenceSteps (optional): Number of inference steps (default: 20, range: 0-100).
Example Input:
{
"seed": 13961,
"width": 512,
"height": 728,
"prompt": "a photo of a redhead girl, unbuttoned white space suit, cleavage, inside spaceship, attractive, looking at viewer, hyperdetailed, closeup",
"strength": 1,
"guidanceScale": 7.5,
"schedulerType": "Euler A Karras",
"negativePrompt": "deformed, disfigured, poorly drawn face, bad anatomy, extra limb, missing limb, mutated hands, mutated fingers, blurry, extra legs, extra arms, extra feet, out of frame, cross-eye",
"numberOfOutputs": 1,
"numberOfInferenceSteps": 30
}
Output: The action returns a list of image URLs generated based on the provided input. Here’s a sample output:
[
"https://assets.cognitiveactions.com/invocations/eb828881-4779-4fbc-bc9d-75cdd7b0ba2f/f77dde50-284b-48ea-81bf-9f3717cfa496.png"
]
Conceptual Usage Example (Python): Here’s how you might invoke 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 = "1db34f9a-844a-4d7f-99ee-94f8d85c0abd" # Action ID for Generate and Edit Images with Reliberate v3
# Construct the input payload based on the action's requirements
payload = {
"seed": 13961,
"width": 512,
"height": 728,
"prompt": "a photo of a redhead girl, unbuttoned white space suit, cleavage, inside spaceship, attractive, looking at viewer, hyperdetailed, closeup",
"strength": 1,
"guidanceScale": 7.5,
"schedulerType": "Euler A Karras",
"negativePrompt": "deformed, disfigured, poorly drawn face, bad anatomy, extra limb, missing limb, mutated hands, mutated fingers, blurry, extra legs, extra arms, extra feet, out of frame, cross-eye",
"numberOfOutputs": 1,
"numberOfInferenceSteps": 30
}
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 action_id corresponds to the Generate and Edit Images action, and the payload is structured according to the input schema.
Conclusion
The Reliberate v3 Cognitive Actions empower developers to generate and edit images seamlessly, offering a broad range of customization options. By leveraging the capabilities outlined in this guide, you can enhance your applications with dynamic visual content tailored to your needs. Explore further by experimenting with different prompts and parameters, and unlock the full potential of image generation in your projects!