Generate Images Like a Pro: A Developer's Guide to shewanart/shewanai Cognitive Actions

The shewanart/shewanai API offers powerful Cognitive Actions designed for image generation, enabling developers to create stunning visuals from text prompts. By leveraging these pre-built actions, you can automate complex image creation processes, apply custom settings, and enhance the quality of the outputs—all while saving valuable development time.
Prerequisites
Before you dive into using the Cognitive Actions, ensure you have the following:
- An API key for the shewanart/shewanai platform, which will be required for authentication.
- Familiarity with JSON structure as you'll be working with input and output payloads.
- Basic knowledge of Python, as we will provide a conceptual code snippet to guide you through making the API calls.
Authentication typically involves passing your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Generate Image with Custom Mask and Settings
Description:
This action allows you to generate an image from a text prompt while offering options for image inpainting with a custom mask. You can adjust the resolution and aspect ratio, toggle speed and quality settings, and apply LoRA (Low-Rank Adaptation) to enhance the generated images.
Category: image-generation
Input
The input schema for this action requires the following fields:
- prompt (required): The text description for the image you want to create.
- mask (optional): A URI pointing to an image mask for inpainting.
- image (optional): A URI for an input image used in image-to-image translation.
- width (optional): Width of the generated image (in pixels).
- height (optional): Height of the generated image (in pixels).
- outputCount (optional): Number of images to generate (1 to 4).
- modelWeights (optional): Load weights for LoRA applications.
- mainLoraScale (optional): Intensity of the main LoRA application.
- additionalLora (optional): Load additional LoRA weights.
- enableFastMode (optional): Toggle for speed optimization.
- inferenceModel (optional): Select the inference model to use.
- promptIntensity (optional): Strength of the prompt in image generation.
- approxMegapixels (optional): Estimated megapixels of the image.
- imageAspectRatio (optional): Aspect ratio of the generated image.
- guidanceIntensity (optional): Scale for guiding the image generation.
- imageOutputFormat (optional): The output format of the image (webp, jpg, png).
- imageOutputQuality (optional): Quality setting for the output image.
- additionalLoraScale (optional): Scale for additional LoRA applications.
- bypassSafetyChecker (optional): Option to disable safety checking.
- inferenceStepsCount (optional): Number of steps for denoising during generation.
Example Input JSON:
{
"prompt": "ein man shewanai mit kamara",
"outputCount": 1,
"mainLoraScale": 1,
"enableFastMode": false,
"inferenceModel": "dev",
"promptIntensity": 0.8,
"approxMegapixels": "1",
"imageAspectRatio": "1:1",
"guidanceIntensity": 3,
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"inferenceStepsCount": 28
}
Output
The action typically returns an array of URIs pointing to the generated images. Here's an example output:
[
"https://assets.cognitiveactions.com/invocations/e89232da-7e7b-4119-af94-8656b706b35f/16f03e0c-a324-4633-be0e-163230e39dec.webp"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet that demonstrates how to call the Cognitive Actions execution endpoint for this 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 = "3c69c993-8e27-4c48-811a-fdaffbb86489" # Action ID for Generate Image with Custom Mask and Settings
# Construct the input payload based on the action's requirements
payload = {
"prompt": "ein man shewanai mit kamara",
"outputCount": 1,
"mainLoraScale": 1,
"enableFastMode": False,
"inferenceModel": "dev",
"promptIntensity": 0.8,
"approxMegapixels": "1",
"imageAspectRatio": "1:1",
"guidanceIntensity": 3,
"imageOutputFormat": "webp",
"imageOutputQuality": 80,
"additionalLoraScale": 1,
"inferenceStepsCount": 28
}
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_idis set to the ID for generating images. - The input payload is structured according to the action's requirements.
Conclusion
With the shewanart/shewanai Cognitive Actions, developers can effortlessly generate custom images based on textual prompts, applying various settings to enhance the output. Experimenting with different configurations can lead to uniquely tailored results, making it an exciting tool for artists, designers, and developers alike. Start integrating these actions into your applications and unleash your creativity!