Spaces:
Running
Running
Update
Browse files- app.py +22 -1
- examples/objects/object10.png +0 -0
- examples/objects/object25.png +0 -0
app.py
CHANGED
|
@@ -27,6 +27,27 @@ def encode_image_as_base64(image: Image.Image) -> str:
|
|
| 27 |
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def predict(
|
| 31 |
model_type: Literal["schnell", "dev", "pixart"],
|
| 32 |
image_and_mask: EditorValue,
|
|
@@ -177,7 +198,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 177 |
)
|
| 178 |
image_and_mask_examples = gr.Examples(
|
| 179 |
examples=[
|
| 180 |
-
|
| 181 |
for path in Path("./examples/scenes").glob("*.png")
|
| 182 |
],
|
| 183 |
label="Room examples",
|
|
|
|
| 27 |
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 28 |
|
| 29 |
|
| 30 |
+
def make_example(image_path: Path) -> EditorValue:
|
| 31 |
+
background_image = Image.open(image_path)
|
| 32 |
+
background_image = background_image.convert("RGB")
|
| 33 |
+
background = np.array(background_image)
|
| 34 |
+
|
| 35 |
+
mask = np.zeros_like(background)
|
| 36 |
+
|
| 37 |
+
layer = np.zeros((background.shape[0], background.shape[1], 4), dtype=np.uint8)
|
| 38 |
+
layer[:, :, 3] = mask
|
| 39 |
+
|
| 40 |
+
composite = np.zeros((background.shape[0], background.shape[1], 4), dtype=np.uint8)
|
| 41 |
+
composite[:, :, :3] = background
|
| 42 |
+
composite[:, :, 3] = np.where(mask == 255, 0, 255) # noqa: PLR2004
|
| 43 |
+
|
| 44 |
+
return {
|
| 45 |
+
"background": background,
|
| 46 |
+
"layers": [layer],
|
| 47 |
+
"composite": composite,
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
def predict(
|
| 52 |
model_type: Literal["schnell", "dev", "pixart"],
|
| 53 |
image_and_mask: EditorValue,
|
|
|
|
| 198 |
)
|
| 199 |
image_and_mask_examples = gr.Examples(
|
| 200 |
examples=[
|
| 201 |
+
make_example(path)
|
| 202 |
for path in Path("./examples/scenes").glob("*.png")
|
| 203 |
],
|
| 204 |
label="Room examples",
|
examples/objects/object10.png
CHANGED
|
|
examples/objects/object25.png
DELETED
|
Binary file (303 kB)
|
|
|