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)
2. Get results faster with webhooks (Recommended)
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.
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
Trigger: When a new image is added to a designated Google Drive folder.
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:
Deep Image AI Zapier Integrations: Explore various integration possibilities - https://zapier.com/apps/deep-image/integrations
Integration Guide: Step-by-step instructions on creating your first Zap with Deep Image AI - https://deep-image.ai/blog/deep-image-now-fully-integrated-with-zapier-quick-guide-for-your-first-zap
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
Trigger: Receive a new image through a Telegram Bot.
Action: Process the image using Deep Image AI's enhancement features.
Action: Save the enhanced image to a Dropbox folder.
This workflow automates the entire process from image reception to storage.
Resources:
Deep Image AI Make Integrations: Discover integration options and modules available - https://www.make.com/en/integrations/deep-image-ai
Integration Guide: Learn how to integrate photo enhancements with other tools using Make - https://deep-image.ai/blog/how-to-use-make-com-to-integrate-photo-enhancements-with-other-tools
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