Create Stunning Custom Images with Image Generation and Inpainting API

The Image Generation and Inpainting API offers developers a powerful tool to create and customize images through advanced AI techniques. Utilizing image-to-image generation and inpainting modes, this API allows you to generate high-quality, tailored visuals based on specific prompts and parameters. With options to control aspects like image dimensions, quality, and style, you can produce stunning images that meet your creative needs quickly and efficiently.
Common Use Cases:
- Creative Industries: Artists and designers can leverage this API to visualize concepts, create artwork, or generate promotional materials.
- Gaming and Entertainment: Game developers can create character designs, environments, and textures on-the-fly, enhancing the immersive experience for players.
- Marketing: Businesses can generate unique images for campaigns, social media, or web content, allowing for a more personalized branding approach.
- Prototyping: Developers can use the API for rapid prototyping of visual elements in applications, saving time and resources during the design phase.
Prerequisites
To start using the Image Generation and Inpainting API, you will need an API key and a basic understanding of making API calls.
Generate Image with Inpainting and LoRA
The "Generate Image with Inpainting and LoRA" action enables you to create customized images using detailed prompts along with the ability to refine images through inpainting. This action is particularly useful for generating specific visuals or altering existing images with precision.
Input Requirements:
- prompt: A detailed text description of the image you want to generate.
- mask (optional): A URI for an image mask used in inpainting mode.
- image (optional): A URI for an input image if you are working with the image-to-image generation.
- model: Choose between 'dev' for comprehensive output or 'schnell' for faster results.
- width & height: Specify dimensions for custom aspect ratios.
- numberOfImages: Define how many images to generate (up to 4).
- additional parameters: Control aspects like LoRA weights, guidance scale, output quality, and more.
Expected Output: The output will be a URI link to the generated image, which can be used directly in applications or for further processing.
Use Cases for this specific action:
- Personalized Content Creation: Generate unique images for blogs, articles, or social media posts based on specific themes or subjects.
- Visual Storytelling: Create custom illustrations for storytelling or narrative-driven projects, enhancing engagement with visually appealing content.
- Rapid Prototyping: Quickly visualize design ideas or marketing concepts, enabling faster iteration and feedback.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "36eb49b1-aee1-45b1-82a8-1811cf6ce8a2" # Action ID for: Generate Image with Inpainting and LoRA
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"model": "dev",
"prompt": "TOKLEE wearing a black tracksuit and black cap in new york mixing studio laying vocals in the booth headphones and reading lyrics from a piece of paper, TOKLEE is standing and behind the glass, we see the engineer from behind the mixing desk then TOKLEE face on behind the glass of recording booth",
"baseLoraScale": 1,
"guidanceScale": 1.97,
"numberOfImages": 1,
"imageMegapixels": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"fastPredictionMode": false,
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8,
"inferenceStepsCount": 28
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
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 (non-JSON): {e.response.text}")
print("------------------------------------------------")
Conclusion
The Image Generation and Inpainting API empowers developers to harness the power of AI for creating customized images that meet a variety of needs. Whether you're looking to enhance your creative projects, streamline content production, or develop unique visual assets, this API provides the tools necessary to turn your ideas into reality. Start integrating the API today and explore the endless possibilities of image generation!