Create Stunning Images with Inpainting Using Miralit

In the world of digital content creation, the ability to generate and manipulate images efficiently is paramount. Miralit offers a powerful set of Cognitive Actions that allow developers to generate images with impressive quality and speed. Among these capabilities is the "Generate Image with Inpainting" action, which enables users to create images while offering the flexibility of using masks for inpainting. This feature is particularly beneficial for artists, designers, and content creators who need to produce high-quality visuals quickly and customize their outputs according to specific requirements.
Imagine a scenario where you want to enhance a photo by replacing an unwanted object or adding new elements without starting from scratch. Miralit’s inpainting capabilities allow you to do just that, making it a go-to tool for various applications, including marketing materials, social media posts, and even game design. With the ability to adjust parameters like quality, speed, and image dimensions, Miralit simplifies the image creation process, providing developers with the tools they need to bring their creative visions to life efficiently.
Prerequisites
Before you dive into using Miralit, ensure you have a valid Cognitive Actions API key and a basic understanding of making API calls.
Generate Image with Inpainting
The "Generate Image with Inpainting" action is designed to produce images while enabling users to refine and enhance them using masks. This action can solve the problem of quickly generating high-quality visuals that require specific modifications or artistic touches.
Input Requirements
To use this action, you'll need to provide a variety of inputs:
- Prompt (string): A detailed description of the image you wish to generate.
- Mask (string): A URI for an image mask that defines areas for inpainting.
- Image (string): A URI for an input image if you're using image-to-image generation.
- Model (string): Choose between 'dev' for high-quality outputs or 'schnell' for faster processing.
- Width and Height (integer): Define the dimensions of the generated image.
- Aspect Ratio (string): Select from predefined ratios or set a custom ratio.
- Output Format (string): Specify the image format, such as webp, jpg, or png.
- Guidance Scale (number): Adjust the strength of the diffusion process.
- Num Outputs (integer): Indicate the number of images to generate.
Expected Output
The output will be a URI link to the generated image, which can be accessed and utilized in your projects. For example, a successful response might look like this:
https://assets.cognitiveactions.com/invocations/.../output_image.webp
Use Cases for this Action
- Content Creation: Quickly generate unique images for blog posts, articles, or social media.
- Product Design: Create visuals for product mockups, allowing for easy modifications.
- Game Development: Design characters or environments by integrating inpainting for seamless adjustments.
- Artistic Projects: Enable artists to explore new styles or concepts without the need for extensive manual editing.
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 = "46bf9ceb-9117-4791-936e-064a1b6459ca" # 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",
"goFast": false,
"prompt": "Miralit with her hair in a pony tail, smiling happily, standing holding a pie made of a paper plate and a heap of whipped cream, wearing black knee-high boots, black leather mini-skirt, blue mock neck long-sleeved t-shirt, photorealistic, highly detailed, professional photography, 8k, full height view, outside soft natural light.",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "9:21",
"outputFormat": "webp",
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"imageMegapixels": "1",
"numInferenceSteps": 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 "Generate Image with Inpainting" action from Miralit provides developers with a robust tool for creating and modifying images efficiently. With its customizable parameters and high-quality outputs, this action is perfect for a variety of use cases, from content creation to artistic endeavors. As you explore the capabilities of Miralit, consider how you can leverage these tools to enhance your projects and streamline your workflows. Start integrating this action today and unlock new creative possibilities!