Elevate Your E-Commerce Experience with Virtual Try-On Cognitive Actions

In the world of e-commerce, providing customers with an immersive shopping experience can significantly enhance engagement and sales. The wolverinn/ecommerce-virtual-try-on Cognitive Actions allow developers to integrate cutting-edge virtual try-on capabilities into their applications. By leveraging advanced image-processing techniques, these actions empower users to visualize how apparel looks on them before making a purchase.
Prerequisites
To get started with the Cognitive Actions in this spec, you will need an API key from the Cognitive Actions platform. Authentication typically involves passing your API key in the headers of your HTTP requests to the Cognitive Actions execution endpoint.
Cognitive Actions Overview
Perform Virtual Try-On
The Perform Virtual Try-On action allows you to execute virtual try-on functionality using the Stable Diffusion model combined with IP-Adapter for realistic clothing and face integration. This action falls under the image-processing category.
Input
The following fields are required for the input schema:
- apparelImage (string): A URI pointing to an image that contains clothing and poses of a human.
- personFaceImage (string): A URI pointing to an image of a person's face.
Optional fields include:
- seed (integer): Initializes random number generation. Default: -1.
- steps (integer): Number of steps to be used in the process. Default: 20.
- prompt (string): Describes the desired output style. Default: "RAW photo, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3".
- scheduler (string): Method to schedule steps. Default: "Karras".
- maximumWidth (integer): Maximum output image width in pixels. Default: 1024.
- maximumHeight (integer): Maximum output image height in pixels. Default: 1024.
- opposingPrompt (string): Specifies undesirable elements in the output.
- sampleMethodName (string): The chosen sampling method. Default: "DPM++ 2M SDE".
- configurationScale (integer): Influences the strength of the prompt guidance. Default: 7.
- noiseReductionStrength (number): Determines the strength of noise reduction. Default: 0.75.
- maskedPaddingOnlyPixels (integer): Number of pixels used for padding in masked areas. Default: 4.
Example Input:
{
"seed": -1,
"steps": 25,
"prompt": "RAW photo, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3",
"scheduler": "Karras",
"apparelImage": "https://replicate.delivery/pbxt/KryqVJESqbELpIUmGP5tJzobFAA4qQNSCxtmacoc8eV56xOV/O1CN01Pt5KzK1J8GD1vGim3_%21%212200674960983.jpg",
"maximumWidth": 1024,
"maximumHeight": 1024,
"opposingPrompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation",
"personFaceImage": "https://replicate.delivery/pbxt/Krypy7MKm9yVO5m0dU3hvptvrHCVc4hI9MaNLO1dWCltNMAA/face.jpg",
"sampleMethodName": "DPM++ 2M SDE",
"configurationScale": 7,
"noiseReductionStrength": 0.75,
"maskedPaddingOnlyPixels": 4
}
Output
The action typically returns an array of image URLs showcasing the virtual try-on results. The output structure includes:
- images (array): Contains the generated image URLs.
- payload (object): Provides metadata about the processing details, including the seed, steps, width, height, and prompts used.
Example Output:
{
"images": [
"https://assets.cognitiveactions.com/invocations/fde6a33f-350a-40b7-806d-d2db7f4ebd30/29b7bf0b-2cb3-4eb1-ac21-7f44d7c22235.png"
],
"payload": {
"info": {
"seed": 895559413,
"steps": 25,
"width": 1013,
"height": 1013,
"prompt": "RAW photo, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3",
"negative_prompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation",
"batch_size": 1
}
}
}
Conceptual Usage Example (Python)
To utilize the Perform Virtual Try-On action, you can use the following conceptual Python code snippet:
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 = "e1c9a0fc-be98-43c3-94af-097bc2999344" # Action ID for Perform Virtual Try-On
# Construct the input payload based on the action's requirements
payload = {
"seed": -1,
"steps": 25,
"prompt": "RAW photo, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3",
"scheduler": "Karras",
"apparelImage": "https://replicate.delivery/pbxt/KryqVJESqbELpIUmGP5tJzobFAA4qQNSCxtmacoc8eV56xOV/O1CN01Pt5KzK1J8GD1vGim3_%21%212200674960983.jpg",
"maximumWidth": 1024,
"maximumHeight": 1024,
"opposingPrompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation",
"personFaceImage": "https://replicate.delivery/pbxt/Krypy7MKm9yVO5m0dU3hvptvrHCVc4hI9MaNLO1dWCltNMAA/face.jpg",
"sampleMethodName": "DPM++ 2M SDE",
"configurationScale": 7,
"noiseReductionStrength": 0.75,
"maskedPaddingOnlyPixels": 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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. This snippet demonstrates how to construct the input payload using the required fields and how to handle API responses effectively.
Conclusion
The wolverinn/ecommerce-virtual-try-on Cognitive Actions provide a powerful way to enhance user experience in e-commerce applications by enabling virtual try-on capabilities. By integrating these actions, developers can create engaging and interactive shopping experiences that allow customers to visualize products realistically. Consider exploring additional use cases such as personalized recommendations or augmented reality features to further enrich your application. Happy coding!