Create Stunning Personalized Images with AI Actions

In today's digital landscape, the demand for unique and personalized visual content is at an all-time high. The Cognitive Actions service allows developers to harness the power of AI to generate custom images tailored to specific requirements, making it easier than ever to create engaging content for various applications. With the ability to specify attributes like style, age range, gender, eye color, and ethnicity, developers can produce high-quality, AI-rendered images that resonate with their target audience. This service streamlines the image creation process, saving time and resources while enhancing creativity.
Common use cases for this service include marketing campaigns, social media content, character design for games, and personalized avatars for virtual environments. By leveraging these AI capabilities, developers can significantly elevate their projects and meet the diverse needs of their users.
Prerequisites
To get started with the Cognitive Actions API, you will need an API key and a basic understanding of making API calls.
Generate Custom AiPicture
The "Generate Custom AiPicture" action enables developers to create personalized, AI-generated images that reflect specific user-defined parameters. This action is particularly useful for projects requiring customized visuals, allowing for a high degree of personalization.
Input Requirements
The input for this action consists of a JSON object that includes the following parameters:
- input: A detailed JSON formatted string specifying the style configurations for the image.
- age: The age range for the image subject, selectable from predefined categories.
- gender: The gender of the subject, with options for "woman" or "man."
- eyeColor: The eye color of the subject, with several options to choose from.
- ethnicity: The ethnicity of the subject, allowing for diverse representation.
- safetensors: A URL for safetensors, enhancing image quality when generating the picture.
Example input:
{
"age": "12 et 18 ans",
"input": "{ \"style\": [{\"background\": \"Plage\", \"clothes\": \"Black Suit\", \"number_picture\": 1, \"img2img\": false}, {\"background\": \"Plage\", \"clothes\": \"Black Suit\", \"number_picture\": 4, \"img2img\": true}] }",
"gender": "woman",
"eyeColor": "Je ne sais pas",
"ethnicity": "Je ne sais pas",
"safetensors": "https://huggingface.co/SG161222/RealVisXL_V4.0/resolve/main/RealVisXL_V4.0.safetensors?download=true"
}
Expected Output
Upon successful execution, this action returns an array of URLs pointing to the generated images. Each URL corresponds to a unique image based on the specified input parameters.
Example output:
https://assets.cognitiveactions.com/invocations/f2268905-6ab1-4939-a5d6-5327798c4ffc/51ffa1a8-69f4-46e7-b3d6-fe968358d933.pnghttps://assets.cognitiveactions.com/invocations/f2268905-6ab1-4939-a5d6-5327798c4ffc/d0d1372b-111b-477c-9814-2788c66dec01.png
Use Cases for this Specific Action
This action is ideal for various scenarios, including:
- Marketing and Advertising: Create targeted visuals for campaigns that require specific demographics.
- Gaming: Design characters with customizable attributes to enhance player engagement.
- Social Media: Generate unique images for posts that stand out and attract attention.
- Personalization: Develop avatars or profile pictures that reflect users' preferences.
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 = "bc7be723-c811-452d-a43b-2aa5f584993d" # Action ID for: Generate Custom AiPicture
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"age": "12 et 18 ans",
"input": "{\n \"style\": [\n {\"background\" : \"Plage\", \"clothes\" : \"Black Suit\", \"number_picture\" : 1, \"img2img\" : false},\n {\"background\" : \"Plage\", \"clothes\" : \"Black Suit\", \"number_picture\" : 4, \"img2img\" : true},\n {\"background\" : \"White\", \"clothes\" : \"Blue Shirt\", \"number_picture\" : 4, \"img2img\" : true},\n {\"background\" : \"Alley\", \"clothes\" : \"Black Turtleneck\", \"number_picture\" : 4, \"img2img\" : true}\n ]\n}",
"gender": "woman",
"eyeColor": "Je ne sais pas",
"ethnicity": "Je ne sais pas",
"safetensors": "https://huggingface.co/SG161222/RealVisXL_V4.0/resolve/main/RealVisXL_V4.0.safetensors?download=true"
}
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 Custom AiPicture" action provides a powerful tool for developers seeking to create personalized and high-quality images efficiently. By leveraging the customizable parameters offered, you can engage your audience with tailored visuals that meet their specific needs. As you explore this action, consider how it can be integrated into your projects to enhance user experience and drive creativity. The possibilities are endless, and the impact on your applications can be significant. Start experimenting with AI-generated imagery today!