Create Stunning Images with the DigitalJohn Urban Narrative Cognitive Actions

In today’s digital age, the ability to generate rich, engaging visuals is vital for developers looking to enhance their applications. The DigitalJohn Urban Narrative API offers a powerful Cognitive Action that allows developers to generate images using a combination of descriptive prompts and image masks. This blog post will guide you through how to leverage these capabilities to create stunning visuals tailored to your specific needs.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- An API key for the DigitalJohn Urban Narrative service, which will be required for authentication.
- A basic understanding of JSON, as the Cognitive Actions utilize JSON for input and output structures.
- Familiarity with making HTTP requests, particularly POST requests.
To authenticate your requests, you will typically include your API key in the headers of your requests.
Cognitive Actions Overview
Generate Image Using Mask and Prompt
The Generate Image Using Mask and Prompt action is designed to create images by employing an image mask for inpainting and a descriptive prompt to produce detailed outputs. This action provides options for customizing the speed, quality, and size of the generated images, utilizing either the 'dev' model for high-detail results or the 'schnell' model for faster outputs.
Input
The input for this action is structured as follows:
{
"prompt": "an illustration of a man in new york in the style of URBNAR",
"useModel": "dev",
"loraScale": 1,
"outputCount": 1,
"outputFormat": "png",
"guidanceScale": 3.5,
"outputQuality": 80,
"extraLoraScale": 0.8,
"inferenceSteps": 28,
"imageAspectRatio": "1:1"
}
- Required Fields:
prompt: The descriptive text that guides the image generation.
- Optional Fields:
mask: A URL for the image mask (if inpainting).seed: For reproducible image generation.image: URL of the input image for conversion.width,height: Dimensions of the generated image (ifaspect_ratiois set tocustom).goFast: Boolean to enable faster predictions.outputCount: Number of images to generate (1 to 4).outputFormat: File format of the output images (webp, jpg, png).guidanceScale: Scale factor for guiding the diffusion process.outputQuality: Quality of the saved images.inferenceSteps: Number of denoising steps.imageAspectRatio: Aspect ratio of the generated image.- Additional parameters for LoRA weights and scaling.
Output
The output of this action is a list of URLs pointing to the generated images. Here’s an example of what you might receive:
[
"https://assets.cognitiveactions.com/invocations/69ab8dbe-e03c-44b8-a7aa-6ed8049b22d8/d9bc9c02-1738-46fc-beb3-29ac1e3f23bd.png"
]
This output provides direct links to the images created based on the input specifications.
Conceptual Usage Example (Python)
Here is a conceptual Python code snippet illustrating how to invoke 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 = "0cc0c565-96d4-4037-9d90-a1bc77401a8a" # Action ID for Generate Image Using Mask and Prompt
# Construct the input payload based on the action's requirements
payload = {
"prompt": "an illustration of a man in new york in the style of URBNAR",
"useModel": "dev",
"loraScale": 1,
"outputCount": 1,
"outputFormat": "png",
"guidanceScale": 3.5,
"outputQuality": 80,
"extraLoraScale": 0.8,
"inferenceSteps": 28,
"imageAspectRatio": "1:1"
}
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}
)
response.raise_for_status()
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
payloadvariable is structured according to the requirements outlined above for the image generation action. - The response will contain URLs to the generated images, which can be accessed or processed further.
Conclusion
The DigitalJohn Urban Narrative Cognitive Action for image generation is a powerful tool that allows developers to create visually stunning images programmatically. By using descriptive prompts and customizable parameters, you can enhance your applications with unique visual content.
Explore these capabilities today to add an engaging visual layer to your projects, and consider experimenting with different prompts and parameters to see what works best for your needs!