File size: 1,016 Bytes
e8255bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import base64
import requests
import json

with open("New hairstyle applied.png", "rb") as image_file:
    image_base64 = base64.b64encode(image_file.read())
with open("mask-inverted.png", "rb") as mask_file:
    mask_base64 = base64.b64encode(mask_file.read())

params = {"inputs": {"image": str(image_base64, encoding="utf-8"), "mask": str(mask_base64, encoding="utf-8")}}
#print(f"input params: {params}")

#url = 'https://vibg4peqt9go3gqx.us-east-1.aws.endpoints.huggingface.cloud'
#url = 'http://localhost:5001'
url = 'https://gcjls79f021eqt9p.us-east-1.aws.endpoints.huggingface.cloud'
token = ''

r = requests.post(url, data=json.dumps(params), headers={"Authorization": f"Bearer {token}", "Content-type": "application/json"})

print(f"Status: {r.status_code}")
if r.status_code != 200:
    print(r.text)

response = json.loads(r.text)

image_base64 = response[0]["image"]

with open("image.png", "wb") as image_file:
    image_file.write(base64.b64decode(image_base64))

print("Output written to image.png")