Easy integration

Easy API Integration with Deep Image AI

Deep Image AI makes it easy to process images through a simple API. Follow these steps to use it correctly and avoid common mistakes.


1. Process an Image

There are two processing methods.

The process method sends an image for processing and immediately returns job id.

The process_result method sends an image and waits up to 25 seconds for the result. If the image is processed in time, you get a direct link to the final image.

Sending an image with process method and periodically checking the result

import time
import json
from pathlib import Path

from urllib.request import urlretrieve

# using requests library
import requests

API_KEY = REPLACE_WITH_YOUR_API_KEY

headers = {
    'x-api-key': API_KEY,
}

data = {
    "enhancements": ["denoise", "deblur", "light"],
    "width": 2000
}

data_dumped = {"parameters": json.dumps(data)}

with open(YOUR_LOCAL_FILE_TO_SEND, 'rb') as f:
    response = requests.post('https://deep-image.ai/rest_api/process', headers=headers,
                             files={'image': f},
                             data=data_dumped)
    if response.status_code == 200:
        response_json = response.json()
        job_id = response_json["job"]
        result_status = "received"

        while result_status in ['received', 'in_progress', 'not_started']:
            response = requests.get(f'https://deep-image.ai/rest_api/result/{job_id}',
                                    headers=headers)
            response_json = response.json()
            result_status = response_json['status']
            time.sleep(1)
        if result_status == 'complete':
            p = Path(response_json['result_url'])
            urlretrieve(response_json['result_url'], p.name)

Sending an Image with process_result method and periodically checking the result

import time
import json
from pathlib import Path

from urllib.request import urlretrieve

# using requests library
import requests

API_KEY = REPLACE_WITH_YOUR_API_KEY

headers = {
    'x-api-key': API_KEY,
}

data = {
    "enhancements": ["denoise", "deblur", "light"],
    "width": 2000
}

data_dumped = {"parameters": json.dumps(data)}

with open(YOUR_LOCAL_FILE_TO_SEND, 'rb') as f:
    response = requests.post('https://deep-image.ai/rest_api/process_result', headers=headers,
                             files={'image': f},
                             data=data_dumped)
    if response.status_code == 200:
        response_json = response.json()
        if response_json.get('status') == 'complete':
            p = Path(response_json['result_url'])
            urlretrieve(response_json['result_url'], p.name)
        elif response_json['status'] in ['received', 'in_progress', 'not_started']:
            while response_json['status'] in ['received', 'in_progress', 'not_started']:
                response = requests.get(f'https://deep-image.ai/rest_api/result/{response_json["job"]}',
                                        headers=headers)
                response_json = response.json()
                time.sleep(1)
            if response_json['status'] == 'complete':
                p = Path(response_json['result_url'])
                urlretrieve(response_json['result_url'], p.name)

If you don’t get a result URL, don’t send the image again! Use the job ID to check the status instead.


Instead of checking the status manually, you can set up a webhook. This means Deep Image AI will send you the result automatically when the image is ready.

Why use webhooks?

  • No need to keep checking the status.

  • The result is sent automatically when ready.

Example: Send a Request with a Webhook

payload = {
    "webhook_url": "https://your-server.com:5000/deep-image-webhook",
    "enhancements": ["denoise", "deblur", "light"],
    "width": 2000
}

data_dumped = {"parameters": json.dumps(payload)}

with open("YOUR_LOCAL_FILE_TO_SEND", "rb") as f:
    response = requests.post("https://deep-image.ai/rest_api/process", headers=headers,
                             files={"image": f}, data=data_dumped)

print(response.json())  # Shows job ID

Example: Receiving the Webhook (Flask)

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/deep-image-webhook", methods=["POST"])
def webhook():
    data = request.json
    print("Image is ready:", data["result_url"])
    return jsonify({"status": "received"}), 200

app.run(port=5000)

3. Automate Workflows with Zapier Integration

Zapier enables you to connect Deep Image AI with thousands of other applications, automating tasks seamlessly. For example, you can set up a workflow where images uploaded to a specific folder in Google Drive are automatically enhanced using Deep Image AI.

✅ Example: Automating Image Enhancement with Zapier

  1. Trigger: When a new image is added to a designated Google Drive folder.

  2. Action: Use Deep Image AI to enhance the image automatically.

This setup ensures that every image added to your folder is processed without manual intervention.

Resources:


4. Enhance Automation with Make (Integromat) Integration

Make allows you to build and automate complex workflows by connecting Deep Image AI with numerous other apps. For instance, you can create a scenario where images from a Telegram Bot are automatically processed and stored in Dropbox.

✅ Example: Processing Images via Make

  1. Trigger: Receive a new image through a Telegram Bot.

  2. Action: Process the image using Deep Image AI's enhancement features.

  3. Action: Save the enhanced image to a Dropbox folder.

This workflow automates the entire process from image reception to storage.

Resources:


Summary: Leveraging Automation Platforms

  • Zapier Integration: Automate tasks by connecting Deep Image AI with various apps, enabling workflows like automatic image enhancement upon upload.

  • Make Integration: Design intricate scenarios that process images through Deep Image AI and interact with multiple applications, enhancing efficiency.

By integrating Deep Image AI with these platforms, you can significantly streamline your image processing tasks and improve productivity.

Last updated