Generate Stunning Images with the SelfieNeMo Cognitive Actions

In the realm of image generation, the SelfieNeMo Cognitive Actions offer powerful tools that empower developers to create customized images effortlessly. Leveraging advanced AI models, these actions provide developers with the flexibility to generate images based on various prompts and refine them according to specific needs. This blog post will guide you through the capabilities of the Generate Custom Image action, its input requirements, and how to integrate it into your applications.
Prerequisites
Before diving into the implementation, ensure you have the following:
- An API key from the Cognitive Actions platform to authenticate your requests.
- Familiarity with basic JSON structure and HTTP requests in your programming language of choice.
For authentication, you typically pass your API key in the request headers, as shown in our example code snippets.
Cognitive Actions Overview
Generate Custom Image
The Generate Custom Image action allows you to create a customized image using the SelfieNeMo model. It supports both image-to-image (img2img) and inpainting modes, offering various parameters for refinement and customization. This action provides adjustable settings to control output dimensions, prompt influences, and reproducibility through random seeds.
Input
The input for this action is a JSON object with the following schema:
{
"mask": "string (uri)",
"seed": "integer",
"image": "string (uri)",
"width": "integer",
"height": "integer",
"prompt": "string",
"refine": "string",
"loraScale": "number",
"scheduler": "string",
"numOutputs": "integer",
"refineSteps": "integer",
"customWeights": "string",
"guidanceScale": "number",
"highNoiseFrac": "number",
"applyWatermark": "boolean",
"negativePrompt": "string",
"promptStrength": "number",
"numInferenceSteps": "integer",
"disableSafetyChecker": "boolean"
}
Example Input
Here's an example JSON payload to invoke this action:
{
"width": 1024,
"height": 1024,
"prompt": "a portrait of SelfiesNeMo",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"numOutputs": 1,
"guidanceScale": 7.5,
"highNoiseFrac": 0.8,
"applyWatermark": true,
"negativePrompt": "",
"promptStrength": 0.8,
"numInferenceSteps": 50
}
Output
Upon successful execution, the action returns an array of URLs pointing to the generated images. Here’s an example of the output:
[
"https://assets.cognitiveactions.com/invocations/6dfbddd3-f061-47c9-b9fa-b42e571e308a/47f92d3c-5ad6-49f2-86d6-f5c3deeeac1b.png"
]
Conceptual Usage Example (Python)
To demonstrate how to use the Generate Custom Image action, here’s a conceptual Python code snippet:
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 = "16f57c0c-5296-4e38-a9d5-aba3cc4e149f" # Action ID for Generate Custom Image
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "a portrait of SelfiesNeMo",
"refine": "no_refiner",
"loraScale": 0.6,
"scheduler": "K_EULER",
"numOutputs": 1,
"guidanceScale": 7.5,
"highNoiseFrac": 0.8,
"applyWatermark": True,
"negativePrompt": "",
"promptStrength": 0.8,
"numInferenceSteps": 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}")
In this example, replace the placeholder for the API key and ensure the endpoint matches your implementation. The input payload structure is aligned with the action's requirements, allowing you to generate images effortlessly.
Conclusion
The Generate Custom Image action from the SelfieNeMo Cognitive Actions provides developers with a robust tool for creating customized images with ease. By understanding its capabilities and input requirements, you can enhance your applications with powerful image generation features. Explore various use cases, from artistic creations to content generation, and see how this action can fit into your projects!