Create Stunning Images with Puri’s Inpainting Action

Puri is an innovative image generation service that empowers developers to create stunning visual content with ease. Its Cognitive Actions simplify the process of generating images by utilizing advanced AI techniques, including inpainting capabilities. With Puri, you can generate high-quality images tailored to your specific needs, whether you're designing graphics for a website, creating marketing materials, or enhancing visual storytelling in applications.
The benefits of using Puri's image generation capabilities include rapid output generation, customizable parameters, and the ability to create images that meet specific artistic visions. This makes it a perfect fit for a wide array of use cases, such as creating unique avatars, enhancing illustrations, or generating concept art for projects.
Prerequisites
To get started with Puri, you will need an API key for the Cognitive Actions service and a basic understanding of how to make API calls.
Generate Image with Inpainting
The Generate Image with Inpainting action allows developers to create images based on provided text prompts and specific parameters. This action is particularly useful when you want to generate images with specific aspects, such as dimensions or styles, or when you need to modify existing images using inpainting techniques.
Purpose
This action solves the problem of generating unique images quickly and efficiently. By allowing users to specify dimensions, aspect ratios, and even apply inpainting with an image mask, it caters to a wide range of creative needs.
Input Requirements
To use this action, you must provide a prompt that describes the desired image. Additionally, you can specify optional parameters such as:
- mask: URI of an image mask for inpainting.
- image: URI of an input image for modification.
- width and height: Dimensions for the generated image.
- imageAspectRatio: Defines the aspect ratio of the output image.
- numberOfOutputs: How many images to generate, ranging from 1 to 4.
Expected Output
The output will be a URL pointing to the generated image, which can be in formats like PNG, JPG, or WEBP, depending on your specifications.
Use Cases for this Specific Action
- Creating Custom Avatars: Generate unique avatars based on user specifications for gaming or social applications.
- Marketing Material: Quickly create promotional images that align with brand guidelines.
- Artistic Projects: Generate concept art or illustrations that require specific visual styles or characteristics.
- Image Modification: Enhance existing images by applying inpainting to fill in or modify areas based on user input.
```python
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 = "1d2c88b2-1bcb-4861-95d7-971f20aa025b" # 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": "PURI avatar , man, cartoonish, no hair, portrait style, casual, transparent",
"loraScale": 1,
"guidanceScale": 3.5,
"outputQuality": 90,
"inferenceModel": "dev",
"promptStrength": 0.8,
"numberOfOutputs": 1,
"imageAspectRatio": "4:5",
"imageOutputFormat": "png",
"additionalLoraScale": 1,
"numberOfInferenceSteps": 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
Puri's image generation capabilities, especially through the Generate Image with Inpainting action, provide developers with a powerful tool to create customized visual content efficiently. By leveraging the flexibility of input parameters and the ability to generate high-quality images quickly, Puri stands out as an essential resource for any developer looking to enhance their applications with unique visuals.
As you explore the possibilities with Puri, consider the various applications in your projects and get started on integrating this transformative image generation technology today!