Enhance Your Images with Asrv2's Upscale Action

26 Apr 2025
Enhance Your Images with Asrv2's Upscale Action

In the era of digital content creation, high-quality visuals play a crucial role in capturing audience attention. With Asrv2's powerful image enhancement capabilities, developers can easily upscale images, boosting their resolution and overall quality. The Upscale Image action utilizes the Aura-SR-V2 model, allowing for seamless integration into various applications, whether for e-commerce, social media, or any platform where image clarity matters. This action not only simplifies the process of improving image quality but also supports multiple output formats and customization options, making it an invaluable tool for developers.

Prerequisites

Before diving into the integration, ensure you have a valid Cognitive Actions API key and a basic understanding of API calls.

Upscale Image

The Upscale Image action is designed to enhance the resolution and quality of images, addressing the common issue of pixelation and low-quality visuals. By leveraging the Aura-SR-V2 model, developers can transform ordinary images into stunning visuals that stand out.

Input Requirements:

  • Image: A URI pointing to the input image that you want to upscale. This is a mandatory field.
  • Max Batch Size: An integer that specifies the maximum number of tiles to process in one batch (default is 8, with a maximum of 64). Higher values can expedite processing but may require more GPU memory.
  • Output Format: Choose from 'webp', 'jpg', or 'png' for the generated images. The default format is 'webp'.
  • Output Quality: An integer between 0 and 100 that specifies the compression quality for lossy formats. The default is set to 80.

Expected Output: The output will be a URI link to the upscaled image, allowing for immediate access to the enhanced visual.

Use Cases for this specific action:

  • E-commerce: Improve product images to attract customers and enhance their shopping experience.
  • Social Media: Create visually appealing graphics that stand out on platforms, increasing engagement.
  • Content Creation: Enhance images for blogs, websites, or presentations to ensure high-quality visuals that effectively convey messages.
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 = "183eb225-923b-466c-a531-a69a699c5b75" # Action ID for: Upscale Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "image": "https://replicate.delivery/pbxt/LPXFLjH6x6k4K0eMOAnlRBfyo11ZqaNWV0Nb6OXIZtn3LeeB/0cdd005c-5469-4a59-afba-4937ced60c2c.png",
  "maxBatchSize": 8,
  "outputFormat": "png",
  "outputQuality": 100
}

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

Asrv2's Upscale Image action offers developers a powerful tool for enhancing image quality effortlessly. By integrating this action, you can significantly improve the visual appeal of images across various applications. Whether you're looking to boost the quality for e-commerce products or enhance social media posts, the flexibility and efficiency of this action make it a must-have in your development toolkit. Start integrating today and elevate your visual content to a new standard!