Unleashing Creativity: Integrating Image Generation with 10thecreator/stephenflemming Cognitive Actions

In the world of digital content creation, the ability to generate custom images based on specific prompts can be a game-changer. The 10thecreator/stephenflemming Cognitive Actions provide developers with powerful tools to create stunning visuals using customizable parameters. This blog post will guide you through the Generate Custom Image action, detailing its usage, input requirements, output expectations, and a conceptual example for integration.
Prerequisites
Before diving into the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Familiarity with making HTTP requests in your programming language of choice.
- Basic understanding of JSON format, which is used for input and output data.
Authentication typically involves passing your API key in the request headers, allowing you to securely access the Cognitive Actions.
Cognitive Actions Overview
Generate Custom Image
The Generate Custom Image action allows you to create images using various customizable prompts and models. It supports advanced features such as inpainting, fast mode, and multiple output formats, enabling tailored image generation for diverse applications.
Category: Image Generation
Input
The input for this action requires a JSON object that includes a variety of fields. The most important field is the prompt, which describes the desired image.
Here's the input schema for the action:
- prompt (required): A descriptive prompt for image generation.
- model (optional): Selects the model for inference (default is "dev").
- goFast (optional): Enables fast predictions (default is false).
- width (optional): Specifies the width of the generated image.
- height (optional): Specifies the height of the generated image.
- mask, image, seed, guidanceScale, numberOfOutputs, imageAspectRatio, imageOutputFormat, imageOutputQuality, inferenceStepCount, and several others can also be included for more control over the output.
Example Input:
{
"model": "dev",
"goFast": false,
"prompt": "The setting for SJF is futuristic yet grounded, blending elements of modern technology, finance, and creativity...",
"guidanceScale": 3,
"mainLoraScale": 1,
"imageMegapixels": "1",
"numberOfOutputs": 4,
"imageAspectRatio": "1:1",
"imageOutputFormat": "png",
"imageOutputQuality": 100,
"inferenceStepCount": 28,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8
}
Output
Upon successful execution, the action returns an array of URLs pointing to the generated images. Each URL corresponds to an image created based on the provided prompt and parameters.
Example Output:
[
"https://assets.cognitiveactions.com/invocations/88602676-c521-4e09-9d7f-b435e15051e9/8d4ada95-92bf-4652-89c7-6ca099efc302.png",
"https://assets.cognitiveactions.com/invocations/88602676-c521-4e09-9d7f-b435e15051e9/ae887196-4627-49a7-bd49-a151c7912389.png",
"https://assets.cognitiveactions.com/invocations/88602676-c521-4e09-9d7f-b435e15051e9/da9c7bab-6656-4ce5-ab65-5128ffe6611b.png",
"https://assets.cognitiveactions.com/invocations/88602676-c521-4e09-9d7f-b435e15051e9/f14e103b-af45-4a76-b1c6-0c7f16dcd324.png"
]
Conceptual Usage Example (Python)
Here's a conceptual Python code snippet demonstrating how to call the Generate Custom Image 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 = "ed4a0216-323f-47cb-9bdd-4dd882fc2938" # Action ID for Generate Custom Image
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"prompt": "The setting for SJF is futuristic yet grounded, blending elements of modern technology...",
"guidanceScale": 3,
"mainLoraScale": 1,
"imageMegapixels": "1",
"numberOfOutputs": 4,
"imageAspectRatio": "1:1",
"imageOutputFormat": "png",
"imageOutputQuality": 100,
"inferenceStepCount": 28,
"additionalLoraScale": 1,
"imagePromptStrength": 0.8
}
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_KEYwith your actual API key. - The action ID for the Generate Custom Image action is provided.
- The input payload is constructed according to the required schema.
- The response is handled to print the resulting URLs of the generated images.
Conclusion
The 10thecreator/stephenflemming Cognitive Actions empower developers to create custom images effortlessly, enhancing creative projects and applications. With the flexibility of adjusting prompts and parameters, you can generate visuals that meet specific needs and preferences.
Explore further by integrating this action into your applications, experimenting with different prompts, and tailoring the parameters to see how they affect the output. Happy coding!