Create Custom Images Effortlessly with Interor 2 Inpainting

In the realm of digital content creation, the ability to generate and manipulate images quickly and efficiently is paramount. Interor 2 offers a powerful Cognitive Action called "Generate Image with Inpainting," which leverages advanced inpainting techniques to allow users to integrate or replace specific elements within an image. This action empowers developers to create tailored visuals for various applications, enhancing both creativity and productivity.
With its flexibility and customization options, the Generate Image with Inpainting action can be particularly beneficial in scenarios like product design, marketing materials, game development, and more. By providing detailed prompts and utilizing features like masks and model selections, developers can ensure high-quality outputs that meet their specific needs.
Prerequisites
To get started with the Generate Image with Inpainting action, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.
Generate Image with Inpainting
The "Generate Image with Inpainting" action is designed to create new images by modifying existing ones through inpainting techniques. This allows for detailed customization, making it an ideal solution for developers looking to enhance visual content dynamically.
Input Requirements:
- Prompt: A descriptive text input that guides the image generation. It serves as the primary request to the model, detailing what the output should depict.
- Mask (optional): A URI pointing to an image mask that specifies areas to be altered in the original image.
- Image (optional): A URI for an existing image to be modified.
- Width and Height: Define the size of the output image (applicable only for custom aspect ratios).
- Fast Mode: A toggle for faster predictions using an optimized model.
- Image Format: Select from formats like webp, jpg, or png.
- Image Quality: Set the desired quality level from 0 to 100.
- Denoising Steps: Number of steps for refining the image.
- Inference Model: Choose between different models for optimal results.
- Number of Outputs: Specify how many images to generate.
Expected Output: The action returns one or more generated images based on the provided prompt and parameters. For instance, a successful request may yield URLs to images like:
https://assets.cognitiveactions.com/invocations/d50116a0-3935-4d14-9b51-686186edc6a7/c46186e5-1bff-49ec-aea1-6760c39cb21c.webphttps://assets.cognitiveactions.com/invocations/d50116a0-3935-4d14-9b51-686186edc6a7/39ed7ed4-d0d5-4ad3-bff2-a6dde183a9f4.webphttps://assets.cognitiveactions.com/invocations/d50116a0-3935-4d14-9b51-686186edc6a7/ea35ce6c-3d08-4cc5-bc4c-6742f5ba7d3c.webp
Use Cases for this specific action:
- Marketing and Advertising: Generate tailored images for campaigns, allowing for quick iterations based on feedback.
- Interior Design: Create visualizations of spaces by modifying existing designs to fit client specifications.
- Game Development: Rapidly produce unique assets by altering base images to create variations in characters, environments, or items.
- Content Creation: Enhance blog posts or articles with custom images that align with the written content.
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 = "ac613788-dbc0-4ed3-92f7-5eed9a0e28f0" # 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 = {
"prompt": "interior-2 Imagine a modern office room designed for productivity and comfort. A central desk faces the entrance, equipped with a computer setup: a monitor, keyboard, and mouse. To the right of the monitor, there’s a pen holder filled with writing tools and a notepad beside it. On the left, a framed photograph adds a personal touch, while a desk lamp in the far-left corner provides focused lighting.\n\nWithin arm’s reach on the right side stands a filing cabinet, while a nearby printer station includes a paper supply shelf. A cozy seating area with two chairs and a small coffee table is positioned in the opposite corner from the entrance. Against the left wall, a bookshelf displays books and decorative items. Behind the desk, a mounted whiteboard offers space for quick notes and brainstorming sessions.",
"fastMode": false,
"imageFormat": "webp",
"imageQuality": 80,
"loraStrength": 1,
"denoisingSteps": 28,
"inferenceModel": "dev",
"imageMegapixels": "1",
"numberOfOutputs": 3,
"promptIntensity": 0.8,
"imageAspectRatio": "1:1",
"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
The Generate Image with Inpainting action from Interor 2 provides developers with a robust tool for creating customized images that can adapt to a variety of needs. Whether for marketing, design, or content generation, the ability to manipulate images effectively can significantly streamline workflows and enhance visual content. To get started, explore the action further and consider how it can fit into your projects for maximum impact.