add erase tab
Browse files- app.py +27 -0
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from diffusers import FluxFillPipeline
|
|
| 8 |
from PIL import Image, ImageOps
|
| 9 |
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
| 10 |
import numpy as np
|
|
|
|
| 11 |
|
| 12 |
torch.set_float32_matmul_precision(["high", "highest"][0])
|
| 13 |
|
|
@@ -29,6 +30,7 @@ pipe = FluxFillPipeline.from_pretrained(
|
|
| 29 |
"black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16
|
| 30 |
).to("cuda")
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
def prepare_image_and_mask(
|
| 34 |
image,
|
|
@@ -147,6 +149,10 @@ def mask_generation(image=None, d=None):
|
|
| 147 |
|
| 148 |
return out
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
@spaces.GPU
|
| 152 |
def main(*args):
|
|
@@ -160,6 +166,8 @@ def main(*args):
|
|
| 160 |
return inpaint(*args)
|
| 161 |
elif api_num == 4:
|
| 162 |
return mask_generation(*args)
|
|
|
|
|
|
|
| 163 |
|
| 164 |
|
| 165 |
rmbg_tab = gr.Interface(
|
|
@@ -233,6 +241,25 @@ sam2_tab = gr.Interface(
|
|
| 233 |
cache_examples=False,
|
| 234 |
)
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
demo = gr.TabbedInterface(
|
| 237 |
[rmbg_tab, outpaint_tab, inpaint_tab, sam2_tab],
|
| 238 |
["remove background", "outpainting", "inpainting", "sam2"],
|
|
|
|
| 8 |
from PIL import Image, ImageOps
|
| 9 |
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
| 10 |
import numpy as np
|
| 11 |
+
from simple_lama_inpainting import SimpleLama
|
| 12 |
|
| 13 |
torch.set_float32_matmul_precision(["high", "highest"][0])
|
| 14 |
|
|
|
|
| 30 |
"black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16
|
| 31 |
).to("cuda")
|
| 32 |
|
| 33 |
+
simple_lama = SimpleLama()
|
| 34 |
|
| 35 |
def prepare_image_and_mask(
|
| 36 |
image,
|
|
|
|
| 149 |
|
| 150 |
return out
|
| 151 |
|
| 152 |
+
def erase(image=None,mask=None) :
|
| 153 |
+
image = load_img(image)
|
| 154 |
+
mask = load_img(mask).convert("L")
|
| 155 |
+
return simple_lama(image, mask)
|
| 156 |
|
| 157 |
@spaces.GPU
|
| 158 |
def main(*args):
|
|
|
|
| 166 |
return inpaint(*args)
|
| 167 |
elif api_num == 4:
|
| 168 |
return mask_generation(*args)
|
| 169 |
+
elif api_num == 5 :
|
| 170 |
+
return erase(*args)
|
| 171 |
|
| 172 |
|
| 173 |
rmbg_tab = gr.Interface(
|
|
|
|
| 241 |
cache_examples=False,
|
| 242 |
)
|
| 243 |
|
| 244 |
+
erase_tab = gr.Interface(
|
| 245 |
+
main,
|
| 246 |
+
inputs=[
|
| 247 |
+
gr.Number(5, interactive=False),
|
| 248 |
+
gr.Image(type="pil"),
|
| 249 |
+
gr.Image(type="pil"),
|
| 250 |
+
],
|
| 251 |
+
outputs=gr.Image(),
|
| 252 |
+
examples=[
|
| 253 |
+
[
|
| 254 |
+
5,
|
| 255 |
+
"./assets/rocket.png",
|
| 256 |
+
"./assets/Inpainting mask.png",
|
| 257 |
+
]
|
| 258 |
+
],
|
| 259 |
+
api_name="erase",
|
| 260 |
+
cache_examples=False,
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
demo = gr.TabbedInterface(
|
| 264 |
[rmbg_tab, outpaint_tab, inpaint_tab, sam2_tab],
|
| 265 |
["remove background", "outpainting", "inpainting", "sam2"],
|
requirements.txt
CHANGED
|
@@ -20,4 +20,5 @@ huggingface_hub
|
|
| 20 |
sentencepiece
|
| 21 |
einops
|
| 22 |
git+https://github.com/facebookresearch/sam2.git
|
| 23 |
-
matplotlib
|
|
|
|
|
|
| 20 |
sentencepiece
|
| 21 |
einops
|
| 22 |
git+https://github.com/facebookresearch/sam2.git
|
| 23 |
+
matplotlib
|
| 24 |
+
simple-lama-inpainting
|