Generate Custom Images with Inpainting Using kwiktwikteam/custom_model_4 Actions

Creating custom images has never been easier with the kwiktwikteam/custom_model_4 API. This powerful set of Cognitive Actions is designed to facilitate advanced image generation using inpainting techniques. By leveraging pre-built actions, developers can produce high-quality images tailored to specific needs, control various image parameters, and enhance their applications with innovative visual content.
Prerequisites
To get started with the kwiktwikteam/custom_model_4 Cognitive Actions, you'll need to set up a few things:
- API Key: Obtain an API key from the Cognitive Actions platform to authenticate your requests.
- Basic Setup: Familiarity with making HTTP requests and handling JSON data will be beneficial.
Authentication typically involves including your API key in the request headers, enabling secure access to the Cognitive Actions.
Cognitive Actions Overview
Generate Custom Images with Inpainting
Description: This action allows you to create custom images using advanced inpainting techniques with the 'dev' and 'schnell' models. It provides control over aspect ratios, resolution, and output quality, ensuring precise and high-speed image generation tailored to your requirements.
- Category: Image Generation
Input
The input schema for this action requires the following fields:
- prompt (string, required): Text prompt guiding the image generation. For example, "give me yagyesh4".
- model (string, optional): Choose either 'dev' or 'schnell' for inference. The default is 'dev'.
- loraScale (number, optional): Adjusts the main LoRA application strength, with a default of 1.
- outputFormat (string, optional): Determines the output image format. Defaults to 'webp'.
- outputQuality (integer, optional): Sets the quality of the output image, ranging from 0 to 100, with a default of 80.
- enableFastMode (boolean, optional): Optimize model for faster predictions; defaults to false.
- imageResolution (string, optional): Defines the number of megapixels for the generated image, defaulting to '1'.
- numberOfOutputs (integer, optional): Specifies how many outputs to generate, with a default of 1.
- imageAspectRatio (string, optional): Sets the aspect ratio of the generated image, defaulting to '1:1'.
- additionalLoraScale (number, optional): Adjusts strength of additional LoRA application, with a default of 1.
- inferenceStepsCount (integer, optional): Determines the number of denoising steps, with a default of 28.
- inputPromptStrength (number, optional): Sets the prompt strength for image-to-image processes, defaulting to 0.8.
- diffusionGuidanceScale (number, optional): Controls the guidance level during diffusion, defaulting to 3.
Example Input:
{
"model": "dev",
"prompt": "give me yagyesh4 ",
"loraScale": 1,
"outputFormat": "webp",
"outputQuality": 80,
"enableFastMode": false,
"imageResolution": "1",
"numberOfOutputs": 1,
"imageAspectRatio": "1:1",
"additionalLoraScale": 1,
"inferenceStepsCount": 28,
"inputPromptStrength": 0.8,
"diffusionGuidanceScale": 3
}
Output
The action typically returns a URL to the generated image. For example:
[
"https://assets.cognitiveactions.com/invocations/8807d897-6e41-429f-8da2-ee676bded3d9/58b63a8e-5ff5-4c64-a129-146e248814ed.webp"
]
Conceptual Usage Example (Python)
Here's a conceptual Python code snippet demonstrating how to call this action using a generic Cognitive Actions endpoint:
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 = "72bf0a29-c57f-47d3-8cc5-efea7bdfb5e6" # Action ID for Generate Custom Images with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "give me yagyesh4 ",
"loraScale": 1,
"outputFormat": "webp",
"outputQuality": 80,
"enableFastMode": False,
"imageResolution": "1",
"numberOfOutputs": 1,
"imageAspectRatio": "1:1",
"additionalLoraScale": 1,
"inferenceStepsCount": 28,
"inputPromptStrength": 0.8,
"diffusionGuidanceScale": 3
}
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, replace the placeholder API key and endpoint with your actual credentials. The action ID and the structured input JSON payload are crucial for executing the action properly.
Conclusion
The kwiktwikteam/custom_model_4 Cognitive Actions provide a powerful way to generate customized images with inpainting capabilities. By utilizing these actions, developers can easily integrate advanced image generation into their applications, enhancing user engagement and creativity. Explore the various input parameters to tailor your image creation process, and consider using these actions for diverse applications ranging from art generation to dynamic content creation. Happy coding!