Enhance Your Images with Purikura's Inpainting and Refinement Action

Purikura offers a powerful set of Cognitive Actions designed to elevate your image generation capabilities. One of the standout features is the Generate Image with Inpainting and Refinement action, which allows developers to create stunning visuals by intelligently modifying existing images. This action not only simplifies the creative process but also enhances the quality of the final output through various adjustable parameters.
Imagine a scenario where you have an image that needs a creative touch—whether it’s for a marketing campaign, social media post, or personal project. With this inpainting action, you can seamlessly fill in missing parts of an image, refine details, and ensure that the end product aligns perfectly with your vision. The ability to customize dimensions, apply masks, and utilize prompts means that you can generate images tailored to your specific needs.
Prerequisites
To get started with Purikura's Cognitive Actions, you'll need an API key and a basic understanding of making API calls. This will enable you to integrate the image generation capabilities into your applications efficiently.
Generate Image with Inpainting and Refinement
Purpose
This action generates images using inpaint mode, allowing for detailed customization through various parameters. It solves the problem of needing to modify existing images while maintaining high quality and coherence in the output.
Input Requirements
The input for this action requires a structured request that includes:
- Mask: A URI pointing to an input mask for inpainting, where black areas remain unchanged, and white areas are inpainted.
- Image: A URI pointing to the base image used in img2img or inpainting mode.
- Width & Height: Dimensions of the output image in pixels (default is 1024x1024).
- Prompt: A descriptive text guiding the image generation, specifying style or content.
- Negative Prompt: Text prompts to avoid unwanted features in the image.
- Various adjustable parameters such as
guidanceScale,promptStrength, andnumberOfOutputs.
Expected Output
The output will be a URI pointing to the generated image, which reflects the specified prompts and refinements. For example, a successful output could look like this:
"https://assets.cognitiveactions.com/invocations/1246d43e-8bb2-4f5a-9d2a-0f70fe712e65/ee02281d-e1f0-4c00-a5a2-b8495d79ce35.png"
Use Cases for this Specific Action
- Creative Design: Graphic designers can use this action to generate unique visuals for projects, enabling them to quickly iterate on designs.
- Marketing Material: Marketers can create eye-catching images tailored to specific campaigns by modifying existing visuals.
- Content Creation: Social media managers can enhance their posts with customized images that align with brand aesthetics.
- Art and Illustration: Artists can explore new creative directions by refining images or generating new artwork based on prompts.
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 = "194776b4-7a28-4ec2-9355-f4d8dca0302f" # Action ID for: Generate Image with Inpainting and Refinement
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"width": 1024,
"height": 1024,
"prompt": "In the style of TOK, two guys wearing shades",
"loraScale": 0.6,
"guidanceScale": 7.5,
"applyWatermark": true,
"negativePrompt": "bad composition\nmutated body parts\nblurry image\ndisfigured",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"refinementStyle": "no_refiner",
"highNoiseFraction": 0.8,
"schedulingAlgorithm": "K_EULER",
"numberOfInferenceSteps": 50
}
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
Purikura's Generate Image with Inpainting and Refinement action empowers developers to create tailored images with ease. With its rich set of features, this action not only saves time but also enhances creativity and quality in image generation. Whether you're working on marketing materials, social media content, or artistic projects, this action opens up a world of possibilities.
To get started, integrate this action into your application and experiment with the various parameters to see how they can transform your visuals. The future of image creation is at your fingertips!