Create Stunning Images with Dora's Inpainting Action

In the world of digital content creation, the ability to generate high-quality images efficiently can significantly enhance your projects. Dora, a powerful image processing service, offers a range of Cognitive Actions, including the innovative "Generate Image Using Inpainting" action. This feature allows developers to create photorealistic images by applying an image mask, customizing various characteristics such as aspect ratio, dimensions, and output format. With Dora, developers can leverage advanced image-to-image transformation capabilities, making it easier to produce visually striking content in less time.
Prerequisites
To get started with Dora's Cognitive Actions, you'll need an API key and a basic understanding of how to make API calls. This will enable you to seamlessly integrate the inpainting action into your applications.
Generate Image Using Inpainting
The "Generate Image Using Inpainting" action is designed to create stunning images by applying a mask, allowing for precise edits and transformations. This action caters to a variety of needs, whether you’re looking to fill in missing parts of an image or entirely transform an existing one.
Input Requirements: To utilize this action, you must provide the following key parameters:
- prompt: A detailed description of the image you want to generate.
- mask: An optional image mask for inpainting mode.
- image: An optional input image for image-to-image transformation.
- model: Choose between 'dev' for detailed outputs or 'schnell' for rapid generation.
- aspectRatio: Specify the desired aspect ratio of the generated image.
- width and height: Define the dimensions for custom aspect ratios.
- additional parameters: Such as seed, output format, guidance scale, and more.
Expected Output: The output will be a high-quality image URL, generated based on the provided prompt and mask. For example, the action could return links to images like:
https://assets.cognitiveactions.com/invocations/.../image1.pnghttps://assets.cognitiveactions.com/invocations/.../image2.png
Use Cases for this specific action:
- Content Creation: Ideal for graphic designers and content creators looking to generate unique visuals based on specific prompts or scenarios.
- Marketing Materials: Perfect for marketers who need custom images for campaigns, allowing for targeted visuals that resonate with their audience.
- Social Media Posts: Enhance your social media presence with tailored images that capture attention and engagement.
- Prototyping: Useful in product design and prototyping, where quick visual iterations are needed based on user feedback.
This action's versatility allows you to produce a wide array of images tailored to your specific needs, making it an invaluable tool in a developer's toolkit.
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 = "c8939c19-4c49-4271-85cc-e823e653c6bf" # Action ID for: Generate Image Using 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": "A photorealistic image of dora standing in front of a mirror, taking a mirror selfie. She is wearing a stylish and elegant two-piece outfit. The top is a strapless, fitted black bodice with a smooth, matte finish, hugging the torso snugly, with subtle vertical seam details to accentuate the fit. The fabric of the top is structured, creating a sleek and minimalist look, with no embellishments, buttons, or zippers visible.The skirt starts high-waisted and is made of a lightweight, flowy fabric in pure white, featuring soft, wide pleats that create a dynamic movement as it reaches down to her mid-calf. The pleats are uniform and create an elegant, flowing silhouette that contrasts perfectly with the fitted black top.\n\nHer accessories include a small black patent leather handbag with a short strap, which she holds gracefully in her left hand. She is also wearing glossy black strappy high-heeled shoes with a closed pointed toe, adding to the refined, formal look.\n\nThe setting is a modern, minimalist room, featuring a light-colored dresser with books and a small decorative vase with a single flower. The lighting is natural and soft, enhancing the simplicity and elegance of the outfit and the overall aesthetic",
"loraScale": 1,
"aspectRatio": "9:16",
"outputFormat": "png",
"guidanceScale": 3,
"outputQuality": 90,
"inferenceSteps": 28,
"promptStrength": 0.8,
"numberOfOutputs": 2,
"additionalLoraScale": 1
}
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
Dora's "Generate Image Using Inpainting" action empowers developers to create high-quality, customized images efficiently. With its capability to handle various input parameters and generate stunning visuals, this tool is perfect for a range of applications, from marketing materials to creative content. By integrating this action into your projects, you can streamline your image generation process and elevate your visual content to new heights. Start experimenting with Dora today and unlock the potential of AI-driven image creation!