Create Stunning Mockups with yuni-eng/inpainting Cognitive Actions

In today's digital landscape, the ability to generate dynamic and customized visuals can significantly enhance user engagement and brand identity. The yuni-eng/inpainting API offers a powerful set of Cognitive Actions that utilize in-painting technology powered by Stable Diffusion. With these pre-built actions, developers can create tailored mockups for items like bags, t-shirts, mugs, and billboards, modifying specific areas while preserving others, all through simple API calls.
Prerequisites
Before diving into the integration of the yuni-eng/inpainting Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making HTTP requests in your programming language of choice, particularly for sending JSON payloads.
- Basic understanding of image processing concepts can be beneficial.
Authentication can be handled by passing your API key in the request headers, allowing you to securely access the Cognitive Actions.
Cognitive Actions Overview
Generate Mockup Variations
Description: This action creates customized mockups using in-painting technology. By using masking images, you can guide the design variations while ensuring specific areas are modified and others remain unchanged.
Category: image-generation
Input:
- mask (string, required): A URI to a black and white image serving as a mask for inpainting. White regions are inpainted while black regions are preserved.
- seed (integer, optional): A random seed for image generation (default is 0 for randomization). Reuse a specific seed from output logs for consistent variations.
- image (string, required): The URI of the input image to which inpainting is applied.
- prompt (string, optional): A text description of the desired content in the generated image (default: "nike shoes in billboard").
- guidanceScale (number, optional): Controls how closely the images align with the prompt (default: 7.5, range: 1 to 20).
- negativePrompt (string, optional): Elements to exclude from the generated output, as a comma-separated list (default: common undesirable elements).
- numberOfOutputs (integer, optional): Specifies the number of images to generate (default: 1, max: 4).
- numberOfInferenceSteps (integer, optional): Number of steps for denoising, impacting quality and inference time (default: 100, range: 1 to 500).
Example Input:
{
"mask": "https://replicate.delivery/pbxt/JuynKj9IO2816Mi6Ik3ynj37p9pj3eQypTf0rUjZIhsjL09t/Screenshot%202023-11-21%20at%202.40.57%20PM.png",
"seed": 0,
"image": "https://replicate.delivery/pbxt/JuynKtxWiFnpNEFIcz1UoWHb6WIJUuilToxGyn9ARsks5RR1/totebag.png",
"prompt": "illustration of takashi murakami colored tiger in bag",
"guidanceScale": 20,
"negativePrompt": "poorly drawn hands, poorly drawn feet, poorly drawn face, poorly drawn eyes, extra limbs, disfigured, deformed, bad anatomy, distorted text, incorrect text spelling",
"numberOfOutputs": 1,
"numberOfInferenceSteps": 200
}
Output: The action typically returns a list of URIs pointing to the generated mockup images. For example:
[
"https://assets.cognitiveactions.com/invocations/5820197a-6de2-45e7-9092-74ca003d13d2/319f5a4f-dfb4-4520-b69f-e1af7110166f.png"
]
Conceptual Usage Example (Python): Here’s a conceptual Python code snippet demonstrating how to invoke the "Generate Mockup Variations" action:
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "fb078f0a-d434-49ea-8f9b-1d271bfd51ca" # Action ID for Generate Mockup Variations
# Construct the input payload based on the action's requirements
payload = {
"mask": "https://replicate.delivery/pbxt/JuynKj9IO2816Mi6Ik3ynj37p9pj3eQypTf0rUjZIhsjL09t/Screenshot%202023-11-21%20at%202.40.57%20PM.png",
"seed": 0,
"image": "https://replicate.delivery/pbxt/JuynKtxWiFnpNEFIcz1UoWHb6WIJUuilToxGyn9ARsks5RR1/totebag.png",
"prompt": "illustration of takashi murakami colored tiger in bag",
"guidanceScale": 20,
"negativePrompt": "poorly drawn hands, poorly drawn feet, poorly drawn face, poorly drawn eyes, extra limbs, disfigured, deformed, bad anatomy, distorted text, incorrect text spelling",
"numberOfOutputs": 1,
"numberOfInferenceSteps": 200
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload} # Hypothetical structure
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
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: {e.response.text}")
In this code snippet, the action ID for "Generate Mockup Variations" and the input payload are clearly placed. The endpoint URL and request structure are hypothetical and should be adjusted according to the actual API specifications.
Conclusion
The yuni-eng/inpainting Cognitive Actions empower developers to create stunning and customized visual mockups effortlessly. By leveraging the in-painting capabilities, you can enhance your applications with engaging and unique images tailored to your needs. Consider exploring other use cases such as product design, marketing materials, or personalized merchandise to fully capitalize on the potential of these actions. Happy coding!