Created
December 15, 2020 07:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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