al-livefront commited on
Commit
e8255bd
1 Parent(s): f040cb4

Add test script

Browse files
testing/New hairstyle applied.png ADDED
testing/README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Testing
2
+ This test is to run a custom model on Hugging Face using a python script to produce an 'image.png' file. The script requires there to be two files in the same local directory: `New hairstyle applied.png` and `mask-inverted.png`. The first file is a selfie with a roughly overlaid hairstyle. The second is a mask that specifies the strength of the inpainting in particular areas in the image. I included some sample files, but you can try different ones as well.
3
+
4
+ - Via a Terminal, navigate into the directory with `test-hf.py`, then run these commands:
5
+ - `python3 -m venv venv` # This creates a "venv" - a special area to install dependencies
6
+ - `. venv/bin/activate` # This activates the "venv" so when you install dependencies they go into the venv, instead of installing system-wide.
7
+ - `pip install requests` # This installs the "requests" library, that helps with calling remote web services
8
+ - `python3 test-hf.py` # This calls the endpoint on huggingface
9
+ - You should now have an `image.png` that shows the inpainted hairstyle.
10
+
testing/mask-inverted.png ADDED
testing/test-hf.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import requests
3
+ import json
4
+
5
+ with open("New hairstyle applied.png", "rb") as image_file:
6
+ image_base64 = base64.b64encode(image_file.read())
7
+ with open("mask-inverted.png", "rb") as mask_file:
8
+ mask_base64 = base64.b64encode(mask_file.read())
9
+
10
+ params = {"inputs": {"image": str(image_base64, encoding="utf-8"), "mask": str(mask_base64, encoding="utf-8")}}
11
+ #print(f"input params: {params}")
12
+
13
+ #url = 'https://vibg4peqt9go3gqx.us-east-1.aws.endpoints.huggingface.cloud'
14
+ #url = 'http://localhost:5001'
15
+ url = 'https://gcjls79f021eqt9p.us-east-1.aws.endpoints.huggingface.cloud'
16
+ token = ''
17
+
18
+ r = requests.post(url, data=json.dumps(params), headers={"Authorization": f"Bearer {token}", "Content-type": "application/json"})
19
+
20
+ print(f"Status: {r.status_code}")
21
+ if r.status_code != 200:
22
+ print(r.text)
23
+
24
+ response = json.loads(r.text)
25
+
26
+ image_base64 = response[0]["image"]
27
+
28
+ with open("image.png", "wb") as image_file:
29
+ image_file.write(base64.b64decode(image_base64))
30
+
31
+ print("Output written to image.png")