Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import torch
|
|
| 6 |
from diffusers import StableDiffusionPipeline, ControlNetModel, StableDiffusionControlNetPipeline
|
| 7 |
from diffusers.utils import load_image
|
| 8 |
from peft import PeftModel, LoraConfig
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -38,6 +39,7 @@ def infer(
|
|
| 38 |
ip_adapter_checkbox=False,
|
| 39 |
ip_adapter_scale=0.0,
|
| 40 |
ip_adapter_image=None,
|
|
|
|
| 41 |
progress=gr.Progress(track_tqdm=True),
|
| 42 |
):
|
| 43 |
ckpt_dir='./model_output'
|
|
@@ -116,7 +118,11 @@ def infer(
|
|
| 116 |
|
| 117 |
pipe.to(device)
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
css = """
|
| 122 |
#col-container {
|
|
@@ -184,6 +190,11 @@ with gr.Blocks(css=css, fill_height=True) as demo:
|
|
| 184 |
step=1,
|
| 185 |
value=20, # Replace with defaults that work for your model
|
| 186 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
with gr.Row():
|
| 188 |
controlnet_checkbox = gr.Checkbox(
|
| 189 |
label="ControlNet",
|
|
@@ -283,6 +294,7 @@ with gr.Blocks(css=css, fill_height=True) as demo:
|
|
| 283 |
ip_adapter_checkbox,
|
| 284 |
ip_adapter_scale,
|
| 285 |
ip_adapter_image,
|
|
|
|
| 286 |
],
|
| 287 |
outputs=[result],
|
| 288 |
)
|
|
|
|
| 6 |
from diffusers import StableDiffusionPipeline, ControlNetModel, StableDiffusionControlNetPipeline
|
| 7 |
from diffusers.utils import load_image
|
| 8 |
from peft import PeftModel, LoraConfig
|
| 9 |
+
from rembg import remove
|
| 10 |
|
| 11 |
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 39 |
ip_adapter_checkbox=False,
|
| 40 |
ip_adapter_scale=0.0,
|
| 41 |
ip_adapter_image=None,
|
| 42 |
+
del_background=False,
|
| 43 |
progress=gr.Progress(track_tqdm=True),
|
| 44 |
):
|
| 45 |
ckpt_dir='./model_output'
|
|
|
|
| 118 |
|
| 119 |
pipe.to(device)
|
| 120 |
|
| 121 |
+
if del_background:
|
| 122 |
+
return remove(pipe(**params).images[0])
|
| 123 |
+
else:
|
| 124 |
+
return pipe(**params).images[0]
|
| 125 |
+
|
| 126 |
|
| 127 |
css = """
|
| 128 |
#col-container {
|
|
|
|
| 190 |
step=1,
|
| 191 |
value=20, # Replace with defaults that work for your model
|
| 192 |
)
|
| 193 |
+
with gr.Row():
|
| 194 |
+
del_background = gr.Checkbox(
|
| 195 |
+
label="Delete background?",
|
| 196 |
+
value=False
|
| 197 |
+
)
|
| 198 |
with gr.Row():
|
| 199 |
controlnet_checkbox = gr.Checkbox(
|
| 200 |
label="ControlNet",
|
|
|
|
| 294 |
ip_adapter_checkbox,
|
| 295 |
ip_adapter_scale,
|
| 296 |
ip_adapter_image,
|
| 297 |
+
del_background,
|
| 298 |
],
|
| 299 |
outputs=[result],
|
| 300 |
)
|