Enhance Images Effortlessly with DemoFusion's Cognitive Actions

In the realm of digital media, image enhancement has become a vital aspect for developers aiming to improve visual content quality. The DemoFusion Cognitive Actions provide a powerful way to enhance images with higher resolution and clarity. This API offers a pre-built action that allows developers to upload an image and apply various parameters for optimal enhancement, making it easy to integrate into any application.
Prerequisites
Before you can start using the DemoFusion Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform. This key will be required to authenticate your requests.
- Familiarity with sending HTTP requests and handling JSON data.
For authentication, you will typically pass your API key in the request headers.
Cognitive Actions Overview
Enhance Image Using DemoFusion
Description:
This action generates an enhanced version of an input image with higher resolution. It allows you to upload an initial image along with a custom or auto-generated prompt to achieve improved image quality and clarity.
Category: Image Enhancement
Input
The input for this action requires the following fields, along with several optional parameters:
- image (required): A valid URI pointing to the input image.
Example:https://replicate.delivery/pbxt/K10dBMR5HkR2twsOHUImt6hch8oGy4AuSXnaQT70vayk5OVk/red-flower.jpg - seed (optional): An integer for reproducibility of the results. If left blank, a random seed will be used.
- scale (optional): An integer that defines the scale factor for the input image. Accepted values are 1, 2, or 4. Default is 2.
- sigma (optional): A number representing the standard deviation for the Gaussian filter. Default is 0.8.
- prompt (optional): A string describing the desired output. Default is "A high resolution photo".
- stride (optional): An integer indicating the stride value for local patches. Default is 64.
- autoPrompt (optional): A boolean flag to enable auto-generated prompts. Default is false.
- multiDecoder (optional): A boolean flag to enable the use of multiple decoders. Default is false.
- guidanceScale (optional): A number for classifier-free guidance, ranging from 1 to 50. Default is 8.5.
- viewBatchSize (optional): An integer for batch size used in denoising. Default is 16.
- negativePrompt (optional): A string to avoid undesired elements in the output. Default includes "blurry, ugly, duplicate, poorly drawn, deformed, mosaic".
- numInferenceSteps (optional): An integer for the number of denoising steps, with a valid range from 1 to 500. Default is 40.
- cosineScaleSkipResidual (optional): A number controlling the strength of skip-residual connections. Default is 3.
- cosineScaleGaussianFilter (optional): A number controlling the strength of the Gaussian filter. Default is 1.
- cosineScaleDilatedSampling (optional): A number controlling the strength of dilated sampling. Default is 1.
Example Input
{
"image": "https://replicate.delivery/pbxt/K10dBMR5HkR2twsOHUImt6hch8oGy4AuSXnaQT70vayk5OVk/red-flower.jpg",
"scale": 2,
"sigma": 0.8,
"stride": 64,
"autoPrompt": true,
"multiDecoder": false,
"guidanceScale": 8.5,
"viewBatchSize": 16,
"negativePrompt": "blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
"numInferenceSteps": 40,
"cosineScaleSkipResidual": 3,
"cosineScaleGaussianFilter": 1,
"cosineScaleDilatedSampling": 1
}
Output
The action typically returns a URL to the enhanced image.
Example Output:https://assets.cognitiveactions.com/invocations/7a206a6c-e96d-490a-abe8-9a4046c6e654/7e87a628-4cd2-49c4-93b0-5903679a92d9.png
Conceptual Usage Example (Python)
Here’s a conceptual snippet demonstrating how to call the Cognitive Actions endpoint to enhance 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 = "401f7476-1815-4793-a9ef-9e477ddc597e" # Action ID for Enhance Image Using DemoFusion
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/K10dBMR5HkR2twsOHUImt6hch8oGy4AuSXnaQT70vayk5OVk/red-flower.jpg",
"scale": 2,
"sigma": 0.8,
"stride": 64,
"autoPrompt": True,
"multiDecoder": False,
"guidanceScale": 8.5,
"viewBatchSize": 16,
"negativePrompt": "blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
"numInferenceSteps": 40,
"cosineScaleSkipResidual": 3,
"cosineScaleGaussianFilter": 1,
"cosineScaleDilatedSampling": 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} # 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, the action ID for "Enhance Image Using DemoFusion" is specified, and the input payload is structured based on the required schema. The output will provide the enhanced image URL upon successful execution.
Conclusion
The DemoFusion Cognitive Action empowers developers to enhance images seamlessly, improving clarity and quality with a few simple parameters. By integrating this action into your applications, you can significantly elevate the visual experience for users. Explore different configurations and see how they can transform your images today!