Enhance Image Quality Effortlessly with Multidiffusion Upscaler

The Multidiffusion Upscaler offers developers a powerful tool for enhancing and upscaling images to high resolutions using advanced diffusion and ControlNet models. This service simplifies the process of image enhancement, enabling you to produce stunning visuals with improved detail and clarity. Whether you are working on applications in graphic design, gaming, or digital marketing, this API can significantly speed up your workflow by providing high-quality outputs in a fraction of the time it would take to do manually.
Prerequisites
To get started with the Multidiffusion Upscaler, you will need an API key for Cognitive Actions and a basic understanding of making API calls.
Enhance and Upscale Image
The Enhance and Upscale Image action is designed to elevate the quality of images by transforming them into high-resolution versions. Utilizing state-of-the-art diffusion techniques, this action ensures that the upscaled images retain their original fidelity while enhancing fine details.
Input Requirements
To use this action, you must provide the following inputs:
- image (URI): The URL of the image you wish to upscale.
- seed (integer): A random seed for generating variations (default: 1337).
- width (integer): Desired output width (default: 512).
- height (integer): Desired output height (default: 512).
- prompt (string): Descriptive input that guides the enhancement process (default: "masterpiece, best quality, highres...").
- Additional parameters such as tileWidth, tileHeight, and various flags for processing options.
Expected Output
The output will be a high-resolution image that reflects the enhancements specified in the input parameters. For example, an output image might look like this:
["https://assets.cognitiveactions.com/invocations/d3a69ee4-5f89-4872-863b-ce5b9d533637/9ed69407-bf40-4469-b8f8-72ec643824a7.png"]
Use Cases for this Specific Action
- Digital Art Enhancement: Artists can upscale their digital creations for prints or high-resolution displays without losing quality.
- E-commerce: Online retailers can improve product images, making them more appealing to customers while ensuring clarity in details.
- Game Development: Developers can enhance textures and graphics, ensuring that the visuals remain sharp and engaging across various resolutions.
- Marketing Materials: Marketers can upscale visuals for presentations, social media, and advertising campaigns, ensuring high-quality imagery that captures attention.
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 = "17cc51cb-d5cb-47d0-ab03-83b1b025be77" # Action ID for: Enhance and Upscale Image
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"seed": 1337,
"image": "https://replicate.delivery/pbxt/KZWaur3VOX61FKuhgCYsMUA7oJDI1tCVyGlTWEV3BIqLZOTe/2024-01-02%2009.18.49.jpg",
"width": 512,
"height": 512,
"prompt": "masterpiece, best quality, highres, <lora:more_details:0.5> <lora:SDXLrender_v2.0:1>",
"tileWidth": 112,
"imageWidth": 1,
"tileHeight": 144,
"fastDecoder": true,
"fastEncoder": true,
"imageHeight": 1,
"tileOverlap": 4,
"moveVaeToGpu": true,
"upscalerName": "4x-UltraSharp",
"renoiseKernel": 3,
"tileBatchSize": 8,
"enableTiledVae": true,
"guidanceFactor": 6,
"inferenceSteps": 18,
"negativePrompt": "(worst quality, low quality, normal quality:2) JuggernautNegative-neg",
"noiseInversion": false,
"allowControlnet": true,
"controlnetModel": "control_v11f1e_sd15_tile",
"decoderTileSize": 192,
"encoderTileSize": 3072,
"numberOfOutputs": 1,
"tileScaleFactor": 2,
"controlnetModule": "tile_resample",
"controlnetWeight": 0.6,
"renoiseIntensity": 0,
"stableDiffuseVae": "vae-ft-mse-840000-ema-pruned.safetensors",
"controlnetLowVram": false,
"denoisingStrength": 0.35,
"maintainInputSize": true,
"stableDiffuseModel": "juggernaut_reborn.safetensors [338b85bc4f]",
"allowTiledDiffusion": true,
"noiseInversionSteps": 0,
"overwriteDimensions": true,
"schedulingAlgorithm": "DPM++ 3M SDE Karras",
"controlnetDownsample": 1,
"controlnetResizeMode": 1,
"controlnetThresholdA": 1,
"controlnetThresholdB": 1,
"tiledDiffusionMethod": "MultiDiffusion",
"clipTerminationLayers": 1,
"controlnetControlMode": 1,
"controlnetGuidanceEnd": 1,
"controlnetPixelPerfect": true,
"encoderColorCorrection": true,
"controlnetGuidanceStart": 0,
"controlnetPreprocessorResolution": 512
}
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 Multidiffusion Upscaler provides a robust solution for developers looking to enhance image quality efficiently. By integrating the Enhance and Upscale Image action, you can elevate the visual appeal of your projects while saving time and resources. As you explore this tool, consider the myriad of applications it can serve in your workflow, from art and e-commerce to game development and marketing. Start experimenting with the API today to unlock the full potential of your images!