Generate Stunning Images with the samyllapoiema/samy Cognitive Actions

In the realm of image generation, the samyllapoiema/samy API offers developers a powerful way to create high-quality images tailored to their specific needs. Using the Generate Image with Inpainting and Customization action, you can leverage customizable dimensions, quality, and formats while utilizing advanced techniques like image inpainting and prompt-based generation. This pre-built action not only enhances productivity but also allows for optimized performance through model selection.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic knowledge of making HTTP requests and handling JSON data.
- Familiarity with Python (for the provided conceptual examples).
Authentication generally involves passing the API key in the request headers to authorize your application's access to the Cognitive Actions.
Cognitive Actions Overview
Generate Image with Inpainting and Customization
This action generates images with customizable dimensions, quality, and formats, utilizing image inpainting and prompt-based generation. It provides support for model selection aimed at optimizing performance, enabling fast generation and adjustment of image quality.
Input
The input schema for this action requires the following fields:
- prompt (string, required): The text prompt used to generate the image. Including specific trigger words can enhance the training model's ability to create desired attributes in the image.
Optional fields include:
- mask (string, uri): An image mask for inpainting mode, which, if provided, overrides other dimension-related inputs.
- image (string, uri): An input image for inpainting or image-to-image generation.
- width (integer): Width of the generated image (only applicable if 'aspect_ratio' is set to custom).
- height (integer): Height of the generated image (only applicable if 'aspect_ratio' is set to custom).
- goFast (boolean): Enable faster predictions using a model optimized for speed.
- numOutputs (integer): Number of images to generate (default is 1, max is 4).
- aspectRatio (string): The aspect ratio for the generated image, with options including standard ratios and 'custom'.
- outputFormat (string): Format for the output images with options including webp, jpg, and png.
- guidanceScale (number): Controls the influence of the prompt during image generation.
- outputQuality (integer): Quality level of the output images ranging from 0 to 100.
- numInferenceSteps (integer): Number of steps in the denoising process, affecting image detail.
Here’s an example input JSON payload for this action:
{
"goFast": false,
"prompt": "samy a woman sit at a table, with a light in the back, working on your computer ",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"numInferenceSteps": 28
}
Output
The action typically returns a JSON array containing the URLs of the generated images. For example:
[
"https://assets.cognitiveactions.com/invocations/08b497b8-de0a-4876-97c7-25a71078820c/edc8b8b0-69d6-4b43-a718-de324aec785d.webp"
]
This output provides direct access to the generated image, making it easy to display or store as needed.
Conceptual Usage Example (Python)
Here’s how you might call the Cognitive Actions endpoint 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 = "4d9f0b98-bc64-47ae-81f0-7c5e25b5ec49" # Action ID for Generate Image with Inpainting and Customization
# Construct the input payload based on the action's requirements
payload = {
"goFast": False,
"prompt": "samy a woman sit at a table, with a light in the back, working on your computer ",
"loraScale": 1,
"numOutputs": 1,
"aspectRatio": "1:1",
"outputFormat": "webp",
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageMegapixels": "1",
"numInferenceSteps": 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, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key and ensure the endpoint URL matches the Cognitive Actions service. The payload is structured based on the example input schema, and the action ID corresponds to the image generation action.
Conclusion
The samyllapoiema/samy Cognitive Action for image generation provides a versatile and powerful tool for developers looking to create customized images efficiently. By integrating this action into your applications, you can automate the generation process, enhance creativity, and improve user engagement. Consider exploring additional parameters and tweaking them to find the optimal settings for your specific use cases. Happy coding!