-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.py
More file actions
36 lines (30 loc) · 832 Bytes
/
test.py
File metadata and controls
36 lines (30 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import io
import requests
from PIL import Image
import base64
API_KEY = ""
#read test.txt file and get text
file = open("test.txt", 'r')
imgB64 = file.read()
file.close()
def loadImage(image : Image):
imgByteArr = io.BytesIO()
image.save(imgByteArr, format=image.format)
imgByteArr = imgByteArr.getvalue()
return imgByteArr
#convert imageb64 to PIL Image
img = Image.open(io.BytesIO(base64.b64decode(imgB64)))
#load image to byte array
image_file_object = loadImage(img)
r = requests.post('https://clipdrop-api.co/remove-background/v1',
files = {
'image_file': ('car.jpg', image_file_object, 'image/jpeg'),
},
headers = { 'x-api-key': API_KEY}
)
if (r.ok):
image = Image.open(io.BytesIO(r.content))
filename_depth = f"dada_Depth.png"
image.save(filename_depth)
else:
r.raise_for_status()