| | 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")}} |
| | |
| |
|
| | |
| | |
| | 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") |
| |
|