Skip to content

Instantly share code, notes, and snippets.

@uday-cohere
Last active October 16, 2022 07:46
Show Gist options
  • Save uday-cohere/caf58348cf1c3cc4d809841d51fce1f0 to your computer and use it in GitHub Desktop.
Save uday-cohere/caf58348cf1c3cc4d809841d51fce1f0 to your computer and use it in GitHub Desktop.
dev.paint.cohere.ai samples
# Image to Image API
import requests
import base64
# give a path to an image on disk
image = open('init.png', 'rb').read()
bytes = base64.b64encode(image)
bytestr = bytes.decode('utf-8')
host = 'https://dev.paint.cohere.ai/img2img'
response = requests.post(host, json={'prompt': 'California', 'n_samples' : 1, 'n_iter' : 1,
'init_img': bytestr})
# decode image
imageBytes = base64.b64decode(response.json()['image'])
# save to disk
f = open("sample.png", "wb")
f.write(imageBytes)
# Text to Image API
import requests
import base64
host = 'https://dev.paint.cohere.ai/txt2img'
response = requests.post(host, json={'prompt': 'California', 'n_samples' : 1, 'n_iter' : 1})
# decode image
imageBytes = base64.b64decode(response.json()['image']) #decode
# save to disk
f = open("sample.png", "wb")
f.write(imageBytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment