ameerazam08 commited on
Commit
36e28c1
1 Parent(s): 5d133e3

Update app.py

Browse files

Change for Upload mask with checkbox

@patrickvonplaten

Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -16,7 +16,8 @@ def read_content(file_path: str) -> str:
16
 
17
  return content
18
 
19
- def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, strength=1.0, scheduler="EulerDiscreteScheduler"):
 
20
  if negative_prompt == "":
21
  negative_prompt = None
22
  scheduler_class_name = scheduler.split("-")[0]
@@ -31,8 +32,11 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, s
31
  pipe.scheduler = scheduler.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", subfolder="scheduler", **add_kwargs)
32
 
33
  init_image = dict["image"].convert("RGB").resize((1024, 1024))
34
- mask = dict["mask"].convert("RGB").resize((1024, 1024))
35
 
 
 
 
 
36
  output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
37
 
38
  return output.images[0], gr.update(visible=True)
@@ -80,7 +84,9 @@ with image_blocks as demo:
80
  gr.HTML(read_content("header.html"))
81
  with gr.Row():
82
  with gr.Column():
83
- image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload",height=400)
 
 
84
  with gr.Row(elem_id="prompt-container", mobile_collapse=False, equal_height=True):
85
  with gr.Row():
86
  prompt = gr.Textbox(placeholder="Your prompt (what you want in place of what is erased)", show_label=False, elem_id="prompt")
@@ -104,8 +110,8 @@ with image_blocks as demo:
104
  share_button = gr.Button("Share to community", elem_id="share-btn",visible=True)
105
 
106
 
107
- btn.click(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container], api_name='run')
108
- prompt.submit(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
109
  share_button.click(None, [], [], _js=share_js)
110
 
111
  gr.Examples(
 
16
 
17
  return content
18
 
19
+ def predict(dict, mask_image,mask_use,prompt="", negative_prompt="", guidance_scale=7.5, steps=20, strength=1.0, scheduler="EulerDiscreteScheduler"):
20
+ print(dict.keys(),mask_image,mask_use)
21
  if negative_prompt == "":
22
  negative_prompt = None
23
  scheduler_class_name = scheduler.split("-")[0]
 
32
  pipe.scheduler = scheduler.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", subfolder="scheduler", **add_kwargs)
33
 
34
  init_image = dict["image"].convert("RGB").resize((1024, 1024))
 
35
 
36
+ if mask_use:
37
+ mask=mask_image.convert("L").resize((1024, 1024))
38
+ else:
39
+ mask = dict["mask"].convert("RGB").resize((1024, 1024))
40
  output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
41
 
42
  return output.images[0], gr.update(visible=True)
 
84
  gr.HTML(read_content("header.html"))
85
  with gr.Row():
86
  with gr.Column():
87
+ image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="image_upload",height=400)
88
+ mask_image = gr.Image(source='upload', elem_id="mask_upload", type="pil", label="mask_upload",height=400)
89
+ mask_use=gr.Checkbox(label="Use Mask")
90
  with gr.Row(elem_id="prompt-container", mobile_collapse=False, equal_height=True):
91
  with gr.Row():
92
  prompt = gr.Textbox(placeholder="Your prompt (what you want in place of what is erased)", show_label=False, elem_id="prompt")
 
110
  share_button = gr.Button("Share to community", elem_id="share-btn",visible=True)
111
 
112
 
113
+ btn.click(fn=predict, inputs=[image,mask_image,mask_use, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container], api_name='run')
114
+ prompt.submit(fn=predict, inputs=[image,mask_image,mask_use , prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
115
  share_button.click(None, [], [], _js=share_js)
116
 
117
  gr.Examples(