Create Stunning Images with Custom Parameters using hedkace/rs-long Actions

The hedkace/rs-long API provides powerful Cognitive Actions designed for developers looking to integrate advanced image generation capabilities into their applications. With the ability to create images based on descriptive text prompts, this API simplifies complex tasks such as image customization and inpainting. By leveraging pre-built actions, developers can save significant time while enhancing the creative potential of their applications.
These Cognitive Actions are particularly useful in various scenarios. Whether you're building a design tool, creating art applications, or generating unique marketing materials, the ability to customize images based on text prompts opens a world of possibilities. Imagine generating visually striking content for social media, advertisements, or even personalized gifts—all with just a few lines of code.
Prerequisites
To effectively use the hedkace/rs-long Cognitive Actions, you will need an API key for the Cognitive Actions service. A conceptual understanding of how to make API calls and handle JSON responses will also be beneficial.
Generate Image with Custom Parameters
The Generate Image with Custom Parameters action allows you to create images using detailed text prompts. This action supports various parameters that can be customized, including image size, format, and quality, and it offers inpainting capabilities and multiple aspect ratios.
Input Requirements
- prompt (required): A descriptive text guiding the image generation process, e.g., "psychedelic poster of rs-long wearing round circular sun glasses with marijuana plants, mushrooms, aliens in black light colors."
- mask (optional): URI of an image mask for inpainting, which overrides other size parameters.
- seed (optional): An integer seed for deterministic results.
- image (optional): URI of an input image for inpainting or image-to-image transformations.
- width (optional): The width of the image (256-1440 pixels) if aspect ratio is set to 'custom'.
- height (optional): The height of the image (256-1440 pixels) if aspect ratio is set to 'custom'.
- goFast (optional): A boolean to enable faster image generation.
- aspectRatio (optional): Choose from predefined ratios or set a custom ratio.
- numOutputs (optional): The number of images to generate (1-4).
- outputFormat (optional): Choose from 'webp', 'jpg', or 'png'.
- guidanceScale (optional): A scale that influences the image generated; lower values tend to create more realistic images.
- outputQuality (optional): A quality scale for non-png formats (0-100).
- additional parameters for LoRA weights, prompt strength, and inference steps.
Expected Output
The action typically returns an array of image URLs based on the successful generation of images. For example:
[
"https://assets.cognitiveactions.com/invocations/01c9507e-886d-4776-bd08-7f75db0c45e7/77bf2872-8ac1-4b87-bfd4-f8c8bcb70ee2.png"
]
Use Cases for this Specific Action
This action is ideal for developers looking to automate the creation of unique visual content. For instance, you could use it in:
- Creative Applications: Generating custom artwork for graphic design software.
- Marketing Tools: Creating eye-catching images for advertisements based on specific themes or campaigns.
- Social Media: Automatically generating visually appealing posts tailored to different audiences or trends.
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 = "4b42b90f-97fe-48b2-bebe-cf42b78537fe" # Action ID for: Generate Image with Custom Parameters
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"goFast": false,
"prompt": "psychedelic poster of rs-long wearing round circular sun glasses with marijuana plants, mushrooms, aliens in black light colors",
"loraScale": 1,
"modelType": "dev",
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "png",
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"numInferenceSteps": 28,
"imageSizeInMegapixels": "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
The hedkace/rs-long Cognitive Action for generating images with custom parameters provides a flexible and powerful tool for developers aiming to enhance their applications with creative image generation capabilities. By leveraging detailed prompts and a range of customizable options, developers can create unique visual content that meets specific needs across various industries.
As you explore the possibilities with this action, consider experimenting with different parameters to discover the potential of automated image generation in your projects. The value of integrating such a tool is immense, enabling you to deliver innovative solutions that captivate users and elevate your applications.