-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.py
60 lines (47 loc) · 1.38 KB
/
test.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# This file is used to verify your http server acts as expected
# Run it with `python3 test.py``
import requests
import base64
import os
from io import BytesIO
from PIL import Image
TESTS = "tests"
FIXTURES = TESTS + os.sep + "fixtures"
OUTPUT = TESTS + os.sep + "output"
def b64encode_file(filename: str):
with open(os.path.join(FIXTURES, filename), "rb") as file:
return base64.b64encode(file.read()).decode("utf-8")
def output_path(filename: str):
return os.path.join(OUTPUT, filename)
def test(name, json):
print("Running test: " + name)
res = requests.post("http://localhost:8000/", json=json)
json = res.json()
print(json)
image_byte_string = json["image_base64"]
image_encoded = image_byte_string.encode("utf-8")
image_bytes = BytesIO(base64.b64decode(image_encoded))
image = Image.open(image_bytes)
fp = output_path(name + ".jpg")
image.save(fp)
print("Saved " + fp)
print()
test(
"RealESRGAN_x4plus_anime_6B",
{
"modelInputs": {
"input_image": b64encode_file("Anime_Girl.svg.png"),
},
"callInputs": {"MODEL_ID": "RealESRGAN_x4plus_anime_6B"},
},
)
test(
"RealESRGAN_x4plus",
{
"modelInputs": {
"input_image": b64encode_file("Blake_Lively.jpg"),
"face_enhance": True,
},
"callInputs": {"MODEL_ID": "RealESRGAN_x4plus"},
},
)