Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@orjanv
Created December 15, 2020 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orjanv/a53deaeb44af39199b83f1e14c8750da to your computer and use it in GitHub Desktop.
Save orjanv/a53deaeb44af39199b83f1e14c8750da to your computer and use it in GitHub Desktop.
Upload, colorize black and white photographs and download them using deepai.org and python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://deepai.org/machine-learning-model/colorizer
#
import requests
import sys
import subprocess
my_key = 'YOUR_KEY_HERE'
api_url = 'https://api.deepai.org/api/colorizer'
def main():
try:
in_file = sys.argv[1]
out_file = sys.argv[2]
except:
print('\nForgot arguments?\n\t$ python colorize.py in_file outfile')
exit(1)
print('\nUploading your black and white file...')
r = requests.post(
api_url,
#data={'image': 'YOUR_IMAGE_URL', # Not used right now
files={'image': open(in_file, 'rb')},
headers={'api-key': my_key}
)
image_url = r.json().get('output_url')
print('\nDownloading your colorized file...')
subprocess.call(["wget", "-q", "-O", out_file, image_url])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment