Skip to content

Commit 33cd256

Browse files
committed
Dockerfile order, basic test + fixture
1 parent 3675bd3 commit 33cd256

File tree

4 files changed

+78
-6
lines changed

4 files changed

+78
-6
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
88
ENV DEBIAN_FRONTEND=noninteractive
99

1010
# Install git and OpenCV
11-
RUN apt-get update && apt-get install -yqq git libopencv-dev python3-opencv
11+
RUN apt-get update && apt-get install -yqq git
12+
13+
WORKDIR /
14+
15+
COPY root-cache/. /root/.cache
1216

1317
# Compile PyPatchMatch
18+
RUN apt-get install -yqq libopencv-dev python3-opencv
1419
WORKDIR /PyPatchMatch
1520
ADD PyPatchMatch .
1621
RUN make
1722

18-
WORKDIR /
19-
20-
COPY root-cache/. /root/.cache
21-
2223
# Install python packages
2324
RUN pip3 install --upgrade pip
2425
ADD requirements.txt requirements.txt

app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import numpy as np
2121
import skimage
2222
import skimage.measure
23+
import patch_match
2324

2425
MODEL_ID = os.environ.get("MODEL_ID")
2526
PIPELINE = os.environ.get("PIPELINE")
@@ -217,7 +218,7 @@ def inference(all_inputs: dict) -> dict:
217218
sel_buffer = np.array(model_inputs.get("init_image"))
218219
img = sel_buffer[:, :, 0:3]
219220
mask = sel_buffer[:, :, -1]
220-
img = patch_match.inpaint(img, mask=255-mask, patch_size=3)
221+
img = patch_match.inpaint(img, mask=255 - mask, patch_size=3)
221222
model_inputs["init_image"] = PIL.Image.fromarray(img)
222223
mask = 255 - mask
223224
mask = skimage.measure.block_reduce(mask, (8, 8), np.max)

test2.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This file is used to verify your http server acts as expected
2+
# Run it with `python3 test.py``
3+
4+
import requests
5+
import base64
6+
import os
7+
import json
8+
from io import BytesIO
9+
from PIL import Image
10+
from pathlib import Path
11+
12+
TESTS = "tests"
13+
FIXTURES = TESTS + os.sep + "fixtures"
14+
OUTPUT = TESTS + os.sep + "output"
15+
Path(OUTPUT).mkdir(parents=True, exist_ok=True)
16+
17+
18+
def b64encode_file(filename: str):
19+
with open(os.path.join(FIXTURES, filename), "rb") as file:
20+
return base64.b64encode(file.read())
21+
22+
23+
def output_path(filename: str):
24+
return os.path.join(OUTPUT, filename)
25+
26+
27+
def decode_and_save(image_byte_string: str, name: str):
28+
image_encoded = image_byte_string.encode("utf-8")
29+
image_bytes = BytesIO(base64.b64decode(image_encoded))
30+
image = Image.open(image_bytes)
31+
fp = output_path(name + ".png")
32+
image.save(fp)
33+
print("Saved " + fp)
34+
35+
36+
def test(name, inputs):
37+
print("Running test: " + name)
38+
response = requests.post("http://localhost:8000/", json=inputs)
39+
result = response.json()
40+
41+
if result.get("images_base64", None) == "None":
42+
print(json.dumps(result, indent=4))
43+
print()
44+
return
45+
46+
images_base64 = result.get("images_base64", None)
47+
if images_base64:
48+
for idx, image_byte_string in enumerate(images_base64):
49+
decode_and_save(image_byte_string, f"{name}_{idx}")
50+
else:
51+
decode_and_save(result["image_base64"], name)
52+
53+
print()
54+
55+
56+
test(
57+
"outpaint",
58+
{
59+
"modelInputs": {
60+
"prompt": "girl with a pearl earing standing in a big room",
61+
"init_image": b64encode_file("girl_with_pearl_earing_outpainting_in.png"),
62+
},
63+
"callInputs": {
64+
"MODEL_ID": "CompVis/stable-diffusion-v1-4",
65+
"PIPELINE": "StableDiffusionInpaintPipelineLegacy",
66+
"SCHEDULER": "DDIM", # Note, as of diffusers 0.3.0, no LMS yet
67+
"FILL_MODE": "patchmatch",
68+
},
69+
},
70+
)
63.7 KB
Loading

0 commit comments

Comments
 (0)