Transform Your Images: Enhance Smiles with the Smile Correct Cognitive Actions

In the world of image processing, enhancing facial features can take an ordinary picture to extraordinary levels. The Smile Correct cognitive actions offer developers a powerful way to transform smiles in images, making them look natural and celebrity-like. This article will guide you through how to integrate these cognitive actions into your applications, allowing you to create stunning visual content effortlessly.
Prerequisites
Before diving into the integration of the Smile Correct cognitive actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which will be necessary for authentication.
- Basic knowledge of how to make API calls and handle JSON data.
Conceptually, authentication involves passing your API key in the headers of your requests.
Cognitive Actions Overview
Enhance Smile in Image
The Enhance Smile in Image action is designed to transform and improve the appearance of a smile in any provided image. The result is a natural-looking enhancement that aligns with the aesthetic of celebrity-like teeth while steering clear of unrealistic features.
Input
The input for this action requires a JSON object with the following fields:
- image (required): A URI pointing to an image that contains a single face. An error will occur if no face or more than one face is detected.
- prompt (optional): A text prompt detailing the desired characteristics of the smile transformation. It defaults to a highly specified prompt.
- negativePrompt (optional): Defines attributes to avoid in the output image, helping to prevent undesirable features.
- numberOfOutputs (optional): Specifies the number of output images desired, with a minimum of 1 and a maximum of 4. It defaults to 1.
Example Input:
{
"image": "https://replicate.delivery/pbxt/KtBb0ACMZrZVIIriOD2sTfrQ6MV9TcRlFiRuadrfQDp9Yzp7/NEHRAKB1%20%281%29.jpeg",
"prompt": "photo of perfectsmile smile <lora:lora_perfectsmile_v1_from_v1_160:1>(Beautiful natural teeth,\naligned bite teeth), aligned white teeth, human like teeth, (no teeth gap),\ncelebrity-like teeth, healthy teeth with a perfect smile, not big incisor,good proportion teeth,good proportion smile,",
"negativePrompt": "(deformed teeth, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime), \n(deformed, distorted, abnormal teeth:1.3, disfigured:1.3, large teeth:2),poorly drawn,Fixer, bad anatomy, rabbit teeth, \nwrong anatomy, missing teeth, disconnected teeth, unnatural mouth, bunny teeth,big incisor teeth,disproportionate front teeth,\nbad smile, reflection, crooked teeth, distorted teeth,cropped, out of frame, worst quality, low quality,\njpeg artifacts, ugly, morbid,disfigured, gross proportions,too many teeth,lipstick, lip gloss, \ntoo less teeth, unnatural size teeth, poorly drawn mouth, poorly drawn teeth",
"numberOfOutputs": 4
}
Output
The action typically returns an array of image URLs, representing the enhanced images based on the input provided. Here’s what you might expect as output:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/bdbbc70f-951f-452b-bb42-e743d01405b8/4e2d9822-f11a-4410-9a26-21b96950bbc0.png",
"https://assets.cognitiveactions.com/invocations/bdbbc70f-951f-452b-bb42-e743d01405b8/fe3fbc1f-5805-4ae5-9ff3-c92087e0c0fd.png",
"https://assets.cognitiveactions.com/invocations/bdbbc70f-951f-452b-bb42-e743d01405b8/7e4bcb78-b5d1-4ce4-922e-352ed70db010.png",
"https://assets.cognitiveactions.com/invocations/bdbbc70f-951f-452b-bb42-e743d01405b8/c403d7d1-4d04-43bb-bfdf-89718d4b9952.png"
]
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet to illustrate how you might call the cognitive actions endpoint to enhance smiles in an image.
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 = "96836ee3-9ee7-4189-9cd2-e05157244204" # Action ID for Enhance Smile in Image
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/KtBb0ACMZrZVIIriOD2sTfrQ6MV9TcRlFiRuadrfQDp9Yzp7/NEHRAKB1%20%281%29.jpeg",
"prompt": "photo of perfectsmile smile <lora:lora_perfectsmile_v1_from_v1_160:1>(Beautiful natural teeth,\naligned bite teeth), aligned white teeth, human like teeth, (no teeth gap),\ncelebrity-like teeth, healthy teeth with a perfect smile, not big incisor,good proportion teeth,good proportion smile,",
"negativePrompt": "(deformed teeth, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime), \n(deformed, distorted, abnormal teeth:1.3, disfigured:1.3, large teeth:2),poorly drawn,Fixer, bad anatomy, rabbit teeth, \nwrong anatomy, missing teeth, disconnected teeth, unnatural mouth, bunny teeth,big incisor teeth,disproportionate front teeth,\nbad smile, reflection, crooked teeth, distorted teeth,cropped, out of frame, worst quality, low quality,\njpeg artifacts, ugly, morbid,disfigured, gross proportions,too many teeth,lipstick, lip gloss, \ntoo less teeth, unnatural size teeth, poorly drawn mouth, poorly drawn teeth",
"numberOfOutputs": 4
}
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 snippet, replace the COGNITIVE_ACTIONS_API_KEY and the COGNITIVE_ACTIONS_EXECUTE_URL with your actual API credentials and endpoint. The action ID and the input payload are structured based on the requirements of the Enhance Smile in Image action.
Conclusion
The Smile Correct cognitive actions provide an innovative way to enhance smiles in images, making them look more appealing and natural. By leveraging these actions, developers can easily integrate powerful image processing capabilities into their applications. Consider exploring other use cases or combining this action with other cognitive features for even more stunning visual transformations!