Create Stunning Images with Tomas: Inpainting and Transfer Made Easy

In the world of digital content creation, high-quality images are essential for grabbing attention and conveying messages effectively. The Tomas service offers a powerful set of Cognitive Actions that enable developers to generate stunning images through advanced techniques like inpainting and image-to-image transfer. These actions are designed to provide flexibility and reproducibility in image generation, allowing you to create visuals tailored to your specific needs. Whether you're building applications for marketing, gaming, or art, Tomas simplifies the process of image generation, making it faster and more efficient.
Imagine being able to create beautiful images simply by providing a prompt or an existing image to enhance. With Tomas, you can generate images in various formats and dimensions, ensuring they fit perfectly within your projects. This capability is particularly useful for developers looking to automate content creation or enhance user experiences with custom visuals.
Prerequisites
To get started with Tomas, 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 and Transfer
The Generate Image with Inpainting and Transfer action allows you to create high-quality images by utilizing inpainting and image-to-image transfer techniques. This action is designed to solve the challenge of generating unique visuals based on specific prompts or modifying existing images seamlessly.
Input Requirements
To use this action, you must provide the following inputs:
- prompt (string): A descriptive prompt to guide the image generation, such as "a medieval king TOMAS in the 15th century a portrait, no hair, bold crown, looking drunk, realistic."
- model (string): Choose between "dev" for balanced quality or "schnell" for faster generation.
- image (string): An optional input image for inpainting or image-to-image transfer.
- mask (string): An optional image mask for inpainting mode.
- width (integer) and height (integer): Custom dimensions for the generated image (if aspect_ratio is set to custom).
- imageFormat (string): The desired output format, such as "webp," "jpg," or "png."
- outputCount (integer): Specify the number of images to generate (1 to 4).
- imageQuality (integer): Set the quality of the output images, from 0 (lowest) to 100 (highest).
- Additional parameters include seed, denoising steps, diffusion guidance, and LoRA intensity settings to fine-tune your image generation.
Expected Output
The expected output is a URL pointing to the generated image. For example:
https://assets.cognitiveactions.com/invocations/40cb7af5-a016-488c-8fd8-b24972c7accb/00c5b5e0-8205-4a3c-ad25-960235464b64.webp
Use Cases for this Specific Action
- Marketing Campaigns: Quickly generate custom visuals that align with your brand message, enhancing the appeal of your marketing materials.
- Game Development: Create unique character designs or backgrounds based on prompts, allowing for dynamic content generation within games.
- Art Projects: Experiment with different artistic styles and compositions, using prompts to inspire your creative process.
- Social Media Content: Automate the generation of eye-catching images for posts, ensuring consistent quality and style.
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 = "6c65154a-e503-47d4-94f1-34c9784f6749" # Action ID for: Generate Image with Inpainting and Transfer
# 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 medieval king TOMAS in the 15th century a portrait, no hair, bold crown, looking drunk, realistic",
"imageFormat": "webp",
"outputCount": 1,
"imageQuality": 90,
"loraIntensity": 1,
"denoisingSteps": 50,
"imageAspectRatio": "1:1",
"diffusionGuidance": 3,
"inputPromptIntensity": 0.8,
"additionalLoraIntensity": 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
Tomas provides developers with a powerful toolset for generating stunning images through its Cognitive Actions. With the ability to inpaint and transfer images based on detailed prompts, the potential applications are vast, ranging from marketing to gaming and beyond. By leveraging these capabilities, you can enhance user engagement and streamline content creation processes. Start exploring Tomas today and elevate your digital projects with high-quality visuals tailored to your needs!