-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
35 lines (28 loc) · 1.01 KB
/
test.py
File metadata and controls
35 lines (28 loc) · 1.01 KB
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
# This file is used to verify your http server acts as expected
# Run it with `python3 test.py demo.jpg`
import sys
import requests
import base64
from io import BytesIO
from PIL import Image
img_name = "demo.jpg"
with open(img_name, "rb") as f:
bytes = f.read()
encoded = base64.b64encode(bytes).decode('utf-8')
model_inputs = {
'prompt': 'rihanna best quality, extremely detailed',
'negative_prompt': 'monochrome, lowres, bad anatomy, worst quality, low quality',
'num_inference_steps': 20,
'image_data': encoded
}
res = requests.post('http://localhost:8000/', json = model_inputs)
image_byte_string = res.json()["depth_base64"]
image_encoded = image_byte_string.encode('utf-8')
image_bytes = BytesIO(base64.b64decode(image_encoded))
image = Image.open(image_bytes)
image.save("depth.jpg")
image_byte_string = res.json()["image_base64"]
image_encoded = image_byte_string.encode('utf-8')
image_bytes = BytesIO(base64.b64decode(image_encoded))
image = Image.open(image_bytes)
image.save("output.jpg")