Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ from diffusers import StableDiffusionPipeline, ControlNetModel, StableDiffusionC
|
|
| 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"
|
| 12 |
model_id_default = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
|
@@ -31,13 +33,13 @@ def infer(
|
|
| 31 |
guidance_scale=7.0,
|
| 32 |
lora_scale=1.0,
|
| 33 |
num_inference_steps=20,
|
| 34 |
-
controlnet_checkbox=False,
|
| 35 |
-
controlnet_strength=0.0,
|
| 36 |
-
controlnet_mode="edge_detection",
|
| 37 |
-
controlnet_image=None,
|
| 38 |
-
ip_adapter_checkbox=False,
|
| 39 |
-
ip_adapter_scale=0.0,
|
| 40 |
-
|
| 41 |
progress=gr.Progress(track_tqdm=True),
|
| 42 |
):
|
| 43 |
ckpt_dir='./lora_pussinboots_logos'
|
|
@@ -118,7 +120,13 @@ def infer(
|
|
| 118 |
|
| 119 |
pipe.to(device)
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
examples = [
|
| 124 |
"Puss in Boots wearing a sombrero crosses the Grand Canyon on a tightrope with a guitar.",
|
|
@@ -272,6 +280,17 @@ with gr.Blocks(css=css, fill_height=True) as demo:
|
|
| 272 |
step=32,
|
| 273 |
value=512, # Replace with defaults that work for your model
|
| 274 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 277 |
|
|
@@ -298,7 +317,8 @@ with gr.Blocks(css=css, fill_height=True) as demo:
|
|
| 298 |
controlnet_image,
|
| 299 |
ip_adapter_checkbox,
|
| 300 |
ip_adapter_scale,
|
| 301 |
-
ip_adapter_image,
|
|
|
|
| 302 |
],
|
| 303 |
outputs=[result],
|
| 304 |
)
|
|
|
|
| 7 |
from diffusers.utils import load_image
|
| 8 |
from peft import PeftModel, LoraConfig
|
| 9 |
|
| 10 |
+
from rembg import remove
|
| 11 |
+
|
| 12 |
|
| 13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
model_id_default = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
|
|
|
| 33 |
guidance_scale=7.0,
|
| 34 |
lora_scale=1.0,
|
| 35 |
num_inference_steps=20,
|
| 36 |
+
controlnet_checkbox=False,
|
| 37 |
+
controlnet_strength=0.0,
|
| 38 |
+
controlnet_mode="edge_detection",
|
| 39 |
+
controlnet_image=None,
|
| 40 |
+
ip_adapter_checkbox=False,
|
| 41 |
+
ip_adapter_scale=0.0,
|
| 42 |
+
remove_bg=None,
|
| 43 |
progress=gr.Progress(track_tqdm=True),
|
| 44 |
):
|
| 45 |
ckpt_dir='./lora_pussinboots_logos'
|
|
|
|
| 120 |
|
| 121 |
pipe.to(device)
|
| 122 |
|
| 123 |
+
image = pipe(**params).images[0]
|
| 124 |
+
|
| 125 |
+
# Если выбрано удаление фона
|
| 126 |
+
if remove_bg:
|
| 127 |
+
image = remove(image)
|
| 128 |
+
|
| 129 |
+
return image
|
| 130 |
|
| 131 |
examples = [
|
| 132 |
"Puss in Boots wearing a sombrero crosses the Grand Canyon on a tightrope with a guitar.",
|
|
|
|
| 280 |
step=32,
|
| 281 |
value=512, # Replace with defaults that work for your model
|
| 282 |
)
|
| 283 |
+
|
| 284 |
+
# Удаление фона------------------------------------------------------------------------------------------------
|
| 285 |
+
# Checkbox для удаления фона
|
| 286 |
+
with gr.Blocks():
|
| 287 |
+
remove_bg = gr.Checkbox(
|
| 288 |
+
label="Remove Background",
|
| 289 |
+
value=False,
|
| 290 |
+
interactive=True
|
| 291 |
+
)
|
| 292 |
+
# -------------------------------------------------------------------------------------------------------------
|
| 293 |
+
|
| 294 |
|
| 295 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 296 |
|
|
|
|
| 317 |
controlnet_image,
|
| 318 |
ip_adapter_checkbox,
|
| 319 |
ip_adapter_scale,
|
| 320 |
+
ip_adapter_image,
|
| 321 |
+
remove_bg,
|
| 322 |
],
|
| 323 |
outputs=[result],
|
| 324 |
)
|