Generate Stunning Images with wandji237/yangopub Cognitive Actions

In the world of AI and machine learning, image generation has taken center stage, allowing developers to create stunning visuals from text prompts and existing images. The wandji237/yangopub API provides a powerful Cognitive Action for image generation, leveraging advanced techniques like inpainting and image-to-image transformations. This blog post will guide you through the capabilities of the Generate Image with Inpainting or Image-to-Image action, explaining how to effectively integrate it into your applications.
Prerequisites
Before diving into the integration of Cognitive Actions, ensure you have the following:
- An API key for the wandji237/yangopub service.
- Basic knowledge of JSON and API interactions, particularly with POST requests.
Authentication is typically achieved by including your API key in the request headers, allowing you to securely access the service.
Cognitive Actions Overview
Generate Image with Inpainting or Image-to-Image
The Generate Image with Inpainting or Image-to-Image action allows you to create images using customizable settings. It supports generating images from text prompts, manipulating existing images, and applying various enhancements to achieve desired visual outcomes.
Input
The input schema for this action requires a JSON object with the following fields:
- prompt (required): A descriptive text prompt for generating the image.
- mask (optional): URI of the image mask used in inpainting mode.
- seed (optional): An integer for reproducible image generation.
- image (optional): URI of the input image for image-to-image transformations.
- width (optional): Width of the generated image (if aspect ratio is set to custom).
- height (optional): Height of the generated image (if aspect ratio is set to custom).
- goFast (optional): A boolean to enable fast predictions.
- outputCount (optional): Number of image outputs to generate (1-4).
- guidanceScale (optional): Scale factor guiding the diffusion process.
- outputQuality (optional): Quality level for saving images (0-100).
- inferenceModel (optional): Specifies which model version to use.
- imageAspectRatio (optional): Aspect ratio for the generated image.
Here is an example input JSON payload:
{
"width": 1280,
"height": 720,
"prompt": "Paul drinking a glass of whiskey in a seedy African bar. we are at night. we have blue and red neon lights in this bar. Paul is dressed in a black t-shirt and black jeans. we have an African waitress in this shot but we don't see her face. she is dressed in a black waitress dress and a white t-shirt. realistic image, beautiful night light. cinema atmosphere.",
"loraScale": 1,
"outputCount": 2,
"guidanceScale": 3.5,
"outputQuality": 100,
"extraLoraScale": 2,
"inferenceModel": "schnell",
"promptStrength": 0.8,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"inferenceStepsCount": 28
}
Output
The action returns an array of generated image URLs based on the provided prompt and settings. Here is an example of the expected output:
[
"https://assets.cognitiveactions.com/invocations/b4772a0f-e008-4152-94e3-7ae2f69e6874/ab5bdb0a-69b9-4b33-8fda-590222236fce.png",
"https://assets.cognitiveactions.com/invocations/b4772a0f-e008-4152-94e3-7ae2f69e6874/ee9778de-b379-4deb-b8e7-138825a87ba9.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet demonstrating how to call the Cognitive Actions execution endpoint:
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 = "bb43debd-f9eb-400c-a77d-06b6205b6042" # Action ID for Generate Image with Inpainting or Image-to-Image
# Construct the input payload based on the action's requirements
payload = {
"width": 1280,
"height": 720,
"prompt": "Paul drinking a glass of whiskey in a seedy African bar. we are at night. we have blue and red neon lights in this bar. Paul is dressed in a black t-shirt and black jeans. we have an African waitress in this shot but we don't see her face. she is dressed in a black waitress dress and a white t-shirt. realistic image, beautiful night light. cinema atmosphere.",
"loraScale": 1,
"outputCount": 2,
"guidanceScale": 3.5,
"outputQuality": 100,
"extraLoraScale": 2,
"inferenceModel": "schnell",
"promptStrength": 0.8,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for the image generation action is specified, and the input payload is structured according to the requirements. The response will contain the URLs of the generated images, which can be used as needed.
Conclusion
The wandji237/yangopub Cognitive Action for image generation provides an exciting opportunity to create unique visuals from descriptive prompts and existing images. With customizable options for speed, quality, and various settings, developers can harness its power for creative applications. Explore the possibilities and integrate this action into your projects for stunning results!