Generate Stunning Images with ControlNet Using isomc-stone/test Actions

Integrating advanced image generation capabilities into your applications has never been easier with the isomc-stone/test Cognitive Actions. This API provides a powerful action that lets developers generate images using a specified ControlNet model, along with customizable parameters for dimensions, prompts, and more. By leveraging these pre-built actions, developers can save time and resources while creating visually appealing content tailored to specific needs.
Prerequisites
Before diving into the integration of Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which will allow you to authenticate your requests.
- Basic knowledge of JSON structure as the input and output will be in this format.
Authentication typically involves passing the API key in the headers of your requests, allowing secure access to the Cognitive Actions services.
Cognitive Actions Overview
Generate Image with ControlNet
The Generate Image with ControlNet action enables users to create images based on various customization options, including control net checkpoints and adjustable parameters like width, height, and guidance scale.
- Category: image-generation
Input
The input for this action is a structured JSON object with several fields. Here’s a breakdown:
- image (required): The URI of the control net image.
- seed (optional): A random seed for generating images. If left blank, the seed will be randomized.
- width (optional): Width of the output image in pixels (default: 768, max: 1024 with height 768).
- height (optional): Height of the output image in pixels (default: 768, max: 1024 with width 768).
- prompt (optional): The guiding prompt for image generation (default: "a photo of a residential tower").
- scheduler (optional): The scheduling algorithm for image processing (default: "DPMSolverMultistep").
- controlNet (optional): Type of control net checkpoint to use (default: "canny").
- guidanceScale (optional): Scale of classifier-free guidance (default: 7.5, range: 1-20).
- negativePrompt (optional): A prompt to exclude certain elements from the output image.
- numberOfOutputs (optional): Number of images to output (default: 1, range: 1-4).
- lowRankAdaptation (optional): Select a LoRA model to use (default: "None").
- numberOfInferenceSteps (optional): Number of denoising steps (default: 50, range: 1-500).
Example Input:
{
"image": "https://replicate.delivery/pbxt/KKXchZEbn6U3AqoOb3JaZ0PuJHsQvTSVgay376gMZoWf07FP/cal.jpg",
"width": 768,
"height": 768,
"prompt": "a photo of a residential tower",
"scheduler": "DPMSolverMultistep",
"controlNet": "canny",
"guidanceScale": 7.5,
"numberOfOutputs": 1,
"lowRankAdaptation": "None",
"numberOfInferenceSteps": 50
}
Output
Upon executing this action, the response typically includes an array of URLs pointing to the generated images.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/fcabaa0e-91d7-4ecf-8671-88d909e5b02d/bd62ad33-a1f9-4534-8b15-3acb8135ed7d.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python snippet illustrating how a developer can invoke the Generate Image with ControlNet action:
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 = "1f19d0c8-d2d1-4208-990a-d03a7ca75a30" # Action ID for Generate Image with ControlNet
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/KKXchZEbn6U3AqoOb3JaZ0PuJHsQvTSVgay376gMZoWf07FP/cal.jpg",
"width": 768,
"height": 768,
"prompt": "a photo of a residential tower",
"scheduler": "DPMSolverMultistep",
"controlNet": "canny",
"guidanceScale": 7.5,
"numberOfOutputs": 1,
"lowRankAdaptation": "None",
"numberOfInferenceSteps": 50
}
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}")
This code snippet demonstrates how to set up a request to the Cognitive Actions endpoint, where the action_id and payload are configured based on the action's requirements. Please note that the endpoint URL and request structure are illustrative.
Conclusion
The Generate Image with ControlNet action from the isomc-stone/test API opens up a realm of possibilities for developers looking to enhance their applications with advanced image generation capabilities. With customizable parameters and straightforward integration, you can quickly create stunning images that meet your specific needs. Consider exploring additional use cases or combining this action with other Cognitive Actions to further enrich your application. Happy coding!