Create Stunning Images with Valido's Inpainting Action

Valido offers a powerful solution for developers looking to generate high-quality images with advanced features such as inpainting, customizable output quality, and rapid processing. This set of Cognitive Actions allows users to transform existing images or create new ones with specific prompts, making it ideal for applications in graphic design, marketing, gaming, and more. With capabilities like adjustable aspect ratios, multiple output formats, and enhanced speed options, Valido streamlines the image generation process, giving developers the tools they need to enhance their projects efficiently.
Prerequisites
To utilize Valido's Cognitive Actions, you will need a valid API key and a basic understanding of making API calls.
Generate Image with Inpainting
Purpose
The "Generate Image with Inpainting" action is designed to create images based on user-defined prompts, while also allowing for the modification of existing images through inpainting. This functionality solves the common problem of needing specific visual content that is not readily available, making it particularly useful for developers in creative fields.
Input Requirements
The action requires a structured input that includes:
- prompt: A text description of the desired image (e.g., "Me wearing a black suit inside an elegant villa interior").
- mask: Optional image mask for inpainting mode.
- image: Optional input image for transformation.
- model: Selection of the inference model (either "dev" for detailed images or "schnell" for faster outputs).
- Additional parameters include dimensions, output format, quality settings, and various strengths for adjustments.
Expected Output
The expected output is a URL link to the generated image in the specified format, such as webp, jpg, or png. For example, the generated output might look like:
https://assets.cognitiveactions.com/invocations/4d7cff41-455c-4d59-aa69-ea18d9ba2e03/75b1a3fe-5c86-4746-9752-b402534286af.webp
Use Cases for this Specific Action
- Graphic Design: Quickly generate visuals for promotional materials or digital content based on specific themes or styles.
- Marketing: Create tailored images that resonate with target audiences, enhancing the effectiveness of campaigns.
- Gaming: Produce unique character designs or environments based on detailed prompts, enabling developers to enrich their game worlds.
- Social Media: Generate eye-catching images that align with trending topics or brand messaging, helping to boost engagement.
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 = "3035162c-d107-4116-85cd-0f614b3fd2ac" # Action ID for: Generate Image with Inpainting
# 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": "Me wearing a black suit inside an elegant villa interior",
"enableFastMode": false,
"imageMegapixels": "1",
"numberOfOutputs": 1,
"promptInfluence": 0.8,
"baseLoraStrength": 1,
"imageAspectRatio": "1:1",
"outputImageFormat": "webp",
"imageOutputQuality": 80,
"inferenceStepsCount": 28,
"additionalLoraStrength": 1,
"diffusionGuidanceScale": 3
}
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
Valido's image generation capabilities, particularly through the inpainting action, provide developers with an array of options to create and modify visual content efficiently. By leveraging this technology, you can enhance your projects with unique images tailored to your specific needs. Whether you're working in design, marketing, gaming, or any other creative field, integrating Valido's Cognitive Actions into your workflow can save time and elevate the quality of your outputs. Explore the possibilities today and see how Valido can transform your image generation process!