Create Stunning Custom Images with Cognitive Actions

In today's digital landscape, the ability to generate high-quality images tailored to specific needs has become essential for developers. The "Custom Model 1" service offers powerful Cognitive Actions designed to streamline image generation, allowing developers to create unique visuals with customizable settings. This service not only speeds up the creative process but also simplifies the complexity typically associated with image generation tasks. Whether you're developing a marketing campaign, designing a website, or enhancing an application, this functionality can dramatically improve your workflow.
Prerequisites
To get started with the Custom Model 1, you will need a Cognitive Actions API key and a basic understanding of how to make API calls.
Generate Image with Customization
The "Generate Image with Customization" action empowers developers to create images based on specific parameters, solving the challenge of producing tailored visuals that meet unique requirements.
Purpose
This action allows for extensive customization, such as adjusting the aspect ratio, output quality, and model selection. You can choose between the 'dev' model for high-quality outputs with 28 steps or the 'schnell' model for quicker results with only 4 steps. This flexibility ensures that developers can optimize for either quality or speed based on their project needs.
Input Requirements
The action requires a prompt, which serves as the basis for the generated image. Additionally, developers can provide various optional parameters, such as:
mask: A URI for an image mask for inpainting.image: A URI for input images used for image-to-image transformation.widthandheight: Dimensions for the image when a custom aspect ratio is desired.goFast: A boolean to enable faster predictions.modelType: Choose between 'dev' and 'schnell'.numOutputs: Specify the number of images to generate.
Expected Output
The output will be a URI linking to the generated image, which can be used directly in applications or shared across platforms. The quality of these images can be adjusted based on the provided parameters.
Use Cases for this Action
- Marketing Materials: Quickly generate unique visuals for advertisements or promotional content that align with specific themes or messages.
- Web Design: Create custom graphics tailored to the aesthetic of a website, ensuring a cohesive look and feel.
- Creative Projects: Artists and designers can produce concept art or prototypes by specifying detailed prompts and configurations, streamlining their creative processes.
```python
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "df507552-3856-4e10-a5ad-eb09f1fd7ab1" # Action ID for: Generate Image with Customization
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"goFast": false,
"prompt": "Show YAGYESH sky divining having fun and smiling",
"loraScale": 1,
"modelType": "dev",
"numOutputs": 1,
"guidanceScale": 3,
"outputQuality": 80,
"extraLoraScale": 1,
"promptStrength": 0.8,
"imageMegapixels": "1",
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
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 (non-JSON): {e.response.text}")
print("------------------------------------------------")
### Conclusion
The "Generate Image with Customization" action within the Custom Model 1 service provides developers with a robust tool for creating tailored images quickly and efficiently. By leveraging its customizable settings, you can enhance your projects with high-quality visuals that meet specific requirements. As you explore this functionality, consider how it can be integrated into your applications for improved user engagement and enhanced creative expression. Start experimenting with your prompts and see how you can elevate your digital content!