Enhance Your Applications with Image Generation Using tokaito14/gothic Cognitive Actions

In the world of digital content creation, the ability to generate stunning visuals can set your application apart. The tokaito14/gothic Cognitive Actions offer developers a powerful toolset for image generation, including inpainting capabilities that allow for detailed customization and fine-tuning of outputs. By leveraging these pre-built actions, you can effortlessly integrate advanced image generation features into your applications, enhancing user experiences and creativity.
Prerequisites
Before you begin, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic familiarity with sending HTTP requests and handling JSON payloads.
- Python environment set up with the
requestslibrary installed for making API calls.
For authentication, you will typically pass your API key in the request headers as a Bearer token, allowing you to securely access the Cognitive Actions functionalities.
Cognitive Actions Overview
Generate Image with Inpainting
The Generate Image with Inpainting action allows you to create detailed images using the 'dev' and 'schnell' models. You can customize various parameters such as aspect ratio, image size, guidance scale, and output quality for enhanced results.
Input
The input schema for this action requires the following fields:
- prompt (required): A detailed text description guiding the image generation.
- mask (optional): A URI pointing to the image mask for inpainting mode.
- seed (optional): An integer seed value for reproducibility.
- image (optional): A URI pointing to the input image for image-to-image or inpainting mode.
- width (optional): The width of the generated image (256-1440).
- height (optional): The height of the generated image (256-1440).
- goFast (optional): A boolean to enable faster image generation.
- numOutputs (optional): Number of images to generate (1-4).
- guidanceScale (optional): Adjusts the model's adherence to the prompt (0-10).
- outputQuality (optional): Defines JPEG image quality (0-100).
- inferenceModel (optional): Selects the model for inference ('dev' or 'schnell').
Example Input:
{
"prompt": "A close-up portrait of a woman in a traditional East Asian style, reminiscent of classical Chinese art. Her fair skin is adorned with striking makeup and tribal black tattoos featuring vivid red eyeshadow...",
"loraScale": 1,
"numOutputs": 1,
"guidanceScale": 3.5,
"outputQuality": 95,
"inferenceModel": "dev"
}
Output
The action typically returns a URL to the generated image.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/92448eb5-ac6d-4786-b95e-ce689404b874/cd7e5797-bc12-4313-92ed-c7dafc5f01b1.jpg"
]
Conceptual Usage Example (Python)
Here’s a conceptual example demonstrating how to invoke the Generate Image with Inpainting action using Python:
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 = "52fa1b14-a765-4061-bcf6-3d0ae09ecf55" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "A close-up portrait of a woman in a traditional East Asian style, reminiscent of classical Chinese art. Her fair skin is adorned with striking makeup and tribal black tattoos...",
"loraScale": 1,
"numOutputs": 1,
"guidanceScale": 3.5,
"outputQuality": 95,
"inferenceModel": "dev"
}
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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload is constructed to match the required schema, and the action is executed by sending a POST request to the hypothetical endpoint.
Conclusion
The tokaito14/gothic Cognitive Actions provide developers with an innovative way to generate intricate images through a straightforward API integration. By utilizing the Generate Image with Inpainting action, you can offer users unique visual experiences tailored to their needs. As a next step, consider experimenting with different prompts and parameters to discover the full potential of these image generation capabilities in your applications. Happy coding!