osmr commited on
Commit
d5501ef
·
1 Parent(s): 91a06e4

Add remove-bg

Browse files
Files changed (2) hide show
  1. app.py +9 -0
  2. requirements.txt +2 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import numpy as np
3
  import random
4
  from typing import Optional
 
5
 
6
  # import spaces #[uncomment to use ZeroGPU]
7
  from diffusers import StableDiffusionPipeline, StableDiffusionControlNetPipeline, ControlNetModel
@@ -45,6 +46,8 @@ def infer(lora_model_id: Optional[str] = "osmr/stable-diffusion-v1-4-lora-iv-ghi
45
  ipadapter_scale: float = DEFAULT_IPA_SCALE,
46
  ipadapter_image: object = None,
47
 
 
 
48
  progress = gr.Progress(track_tqdm=True)):
49
 
50
  use_lora = (lora_model_id in [
@@ -133,6 +136,9 @@ def infer(lora_model_id: Optional[str] = "osmr/stable-diffusion-v1-4-lora-iv-ghi
133
  ip_adapter_image=ipadapter_image
134
  ).images[0]
135
 
 
 
 
136
  return image, seed
137
 
138
 
@@ -244,6 +250,8 @@ with gr.Blocks(css=css) as demo:
244
  value=DEFAULT_LS,
245
  )
246
 
 
 
247
  with gr.Accordion("ControlNet Settings", open=False):
248
  controlnet_type = gr.Dropdown(
249
  choices=[
@@ -300,6 +308,7 @@ with gr.Blocks(css=css) as demo:
300
  controlnet_image,
301
  ipadapter_scale,
302
  ipadapter_image,
 
303
  ],
304
  outputs=[result, seed],
305
  )
 
2
  import numpy as np
3
  import random
4
  from typing import Optional
5
+ from rembg import remove
6
 
7
  # import spaces #[uncomment to use ZeroGPU]
8
  from diffusers import StableDiffusionPipeline, StableDiffusionControlNetPipeline, ControlNetModel
 
46
  ipadapter_scale: float = DEFAULT_IPA_SCALE,
47
  ipadapter_image: object = None,
48
 
49
+ do_remove_bg: bool = False,
50
+
51
  progress = gr.Progress(track_tqdm=True)):
52
 
53
  use_lora = (lora_model_id in [
 
136
  ip_adapter_image=ipadapter_image
137
  ).images[0]
138
 
139
+ if do_remove_bg:
140
+ image = remove(image)
141
+
142
  return image, seed
143
 
144
 
 
250
  value=DEFAULT_LS,
251
  )
252
 
253
+ do_remove_bg = gr.Checkbox(label="Remove background", value=False)
254
+
255
  with gr.Accordion("ControlNet Settings", open=False):
256
  controlnet_type = gr.Dropdown(
257
  choices=[
 
308
  controlnet_image,
309
  ipadapter_scale,
310
  ipadapter_image,
311
+ do_remove_bg,
312
  ],
313
  outputs=[result, seed],
314
  )
requirements.txt CHANGED
@@ -5,4 +5,5 @@ invisible_watermark
5
  torch
6
  transformers
7
  xformers
8
- gradio
 
 
5
  torch
6
  transformers
7
  xformers
8
+ gradio
9
+ rembg