Create Stunning Inpainted Images with Looneytunes

In the realm of image generation, the "Looneytunes" service stands out by offering a powerful Cognitive Action that allows developers to create inpainted images from text prompts. This innovative approach not only streamlines the creative process but also provides a high level of customization. With options to adjust output dimensions, apply various refinement techniques, and control prompt strength, Looneytunes simplifies the task of generating visually appealing content.
Imagine a scenario where you want to create an image of an astronaut riding a rainbow unicorn, but with specific areas of the image needing alterations. By using the inpainting capabilities of Looneytunes, you can specify which parts of the image to modify while keeping others intact. This functionality is particularly useful in fields such as marketing, gaming, and content creation, where unique visuals are essential.
Prerequisites
To leverage the power of Looneytunes, you will need a Cognitive Actions API key and a basic understanding of making API calls.
Generate Inpainted Image
Purpose
The "Generate Inpainted Image" action enables developers to create images based on a text prompt while allowing for targeted modifications in specified areas. This action addresses the need for high-quality image generation that can adapt to specific requirements, making it ideal for various applications in creative industries.
Input Requirements
The inputs for this action include:
- Mask: A URI for the input mask where black areas remain unchanged and white areas are modified.
- Image: The URI for the input image to be used.
- Width: Output image width in pixels (default is 1024).
- Height: Output image height in pixels (default is 1024).
- Prompt: Text prompt guiding the image generation.
- Refine: Option to select the refinement style.
- Guidance Scale: Affects the strength of the prompt's influence.
- Apply Watermark: Option to apply a watermark for verification.
- Number of Outputs: Specifies how many images to generate.
For example, a typical input might look like this:
{
"width": 1024,
"height": 1024,
"prompt": "a photo TOK, a simple portrait",
"refine": "no_refiner",
"guidanceScale": 7.5,
"applyWatermark": true,
"numberOfOutputs": 1
}
Expected Output
The action will return a URI for the generated image, which can be directly accessed or displayed. For instance, an example output may look like this:
"https://assets.cognitiveactions.com/invocations/ece34e9b-1a61-451d-bd18-7ec6ebaa88f0/576ec748-7186-4480-9cbb-e34853246052.png"
Use Cases
- Marketing Campaigns: Create tailored visuals for advertisements by modifying existing images to fit specific themes or messages.
- Game Development: Generate unique character designs or environments while keeping certain elements consistent.
- Content Creation: Produce engaging graphics for blogs or social media, allowing for personalized visual storytelling.
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 = "7c7c2655-0db7-4ed2-a720-aac1c47075dc" # Action ID for: Generate Inpainted Image
# 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": "a photo TOK , a simple portrate ",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"guidanceScale": 7.5,
"applyWatermark": true,
"promptStrength": 0.8,
"numberOfOutputs": 1,
"highNoiseFraction": 0.8,
"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
The "Generate Inpainted Image" action from Looneytunes offers significant advantages for developers looking to create customized images quickly and efficiently. By harnessing the power of targeted inpainting, you can enhance your projects with unique visuals that meet specific requirements. Whether for marketing, gaming, or content creation, this action opens up a world of possibilities.
To get started, set up your API key and explore the various parameters to see how you can elevate your image generation efforts with Looneytunes!