Enhance Your Applications with Image Generation Using marloes90/fiersmarloes2 Cognitive Actions

In the realm of artificial intelligence, image generation has emerged as a powerful tool that allows developers to create stunning visuals from textual prompts. The marloes90/fiersmarloes2 Cognitive Actions provide a robust API for generating images using advanced prediction models. These actions enable customized image outputs through various modes like image-to-image and inpainting, making it easier than ever to integrate sophisticated image generation capabilities into your applications.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Familiarity with JSON payloads as they will be used to structure inputs for the actions.
- Basic knowledge of making HTTP requests in your preferred programming language (we'll use Python in examples).
Conceptually, you will pass your API key in the request headers to authenticate your requests.
Cognitive Actions Overview
Generate Image with Prediction
The Generate Image with Prediction action allows you to create images based on customizable inputs. This action supports image generation through various models, focusing on either quality or speed, and includes advanced features like prompt intensity and custom aspect ratios.
- Category: Image Generation
Input
The required fields for this action include:
- prompt (string): The textual description of the image you want to generate.
Optional fields include:
- mask (string): URL of the image mask for inpainting mode.
- seed (integer): A random seed for reproducible generation.
- image (string): Input image for image-to-image or inpainting mode.
- model (string): Specifies the model for inference (
devorschnell). - width and height (integer): Dimensions of the generated image (only applicable if
aspect_ratiois custom). - goFast (boolean): Enables faster predictions with optimized models.
- numOutputs (integer): Number of image outputs to generate.
- guidanceScale (number): Scale for the diffusion process.
- imageAspectRatio (string): Defines the aspect ratio for the generated image.
Here’s an example input JSON structure:
{
"model": "dev",
"prompt": "fiersmarloes2 as a woman, wearing glasses, hair in bun, t shirt, black and white side profile, profesional shoot, inspired by salgado",
"loraScale": 1.07,
"numOutputs": 4,
"guidanceScale": 2.23,
"extraLoraScale": 0.38,
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 50,
"imageOutputQuality": 90
}
Output
Upon successful execution, the action returns an array of URLs pointing to the generated images. Here’s an example of the output structure:
[
"https://assets.cognitiveactions.com/invocations/5f36f0f1-ab60-4a12-8e2c-868136a9170c/1a69c208-ebe9-4b42-b541-323d65493b32.webp",
"https://assets.cognitiveactions.com/invocations/5f36f0f1-ab60-4a12-8e2c-868136a9170c/13e533ed-3b46-4720-80d8-843193e0b448.webp",
"https://assets.cognitiveactions.com/invocations/5f36f0f1-ab60-4a12-8e2c-868136a9170c/08ea7149-691f-4570-b041-7f7b62bd7034.webp",
"https://assets.cognitiveactions.com/invocations/5f36f0f1-ab60-4a12-8e2c-868136a9170c/5abdb7e6-930a-4f32-bdb9-cf67b80758eb.webp"
]
Conceptual Usage Example (Python)
Here's how you might call the Generate Image with Prediction 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 = "f8046db3-8fc3-40cf-ac4f-205326ac4f2a" # Action ID for Generate Image with Prediction
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"prompt": "fiersmarloes2 as a woman, wearing glasses, hair in bun, t shirt, black and white side profile, profesional shoot, inspired by salgado",
"loraScale": 1.07,
"numOutputs": 4,
"guidanceScale": 2.23,
"extraLoraScale": 0.38,
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 50,
"imageOutputQuality": 90
}
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 payload is structured according to the action's requirements, and the response will yield the URLs of the generated images.
Conclusion
Integrating the marloes90/fiersmarloes2 Cognitive Actions into your applications opens up exciting possibilities for generating high-quality images from text prompts. With customizable settings and support for various models, you can create unique visuals tailored to your needs. Now that you have a clear understanding of the Generate Image with Prediction action, consider experimenting with different prompts and configurations to see what creative outputs you can achieve!