multimodalart HF staff commited on
Commit
807ffba
1 Parent(s): dfbd204

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -5,8 +5,8 @@ from diffusers import AutoPipelineForInpainting, UNet2DConditionModel
5
  import diffusers
6
  from share_btn import community_icon_html, loading_icon_html, share_js
7
 
8
- unet = UNet2DConditionModel.from_pretrained("valhalla/sdxl-inpaint-ema", torch_dtype=torch.float16, revision="d5593e75323fa2a5285ebe02c1aba504a695bbf7") # 50k
9
- pipe = AutoPipelineForInpainting.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
10
 
11
  def read_content(file_path: str) -> str:
12
  """read the content of target file
@@ -16,7 +16,7 @@ def read_content(file_path: str) -> str:
16
 
17
  return content
18
 
19
- def predict(dict, prompt="", guidance_scale=7.5, steps=20, strength=1.0, scheduler="EulerDiscreteScheduler"):
20
 
21
  scheduler_class_name = scheduler.split("-")[0]
22
 
@@ -32,7 +32,7 @@ def predict(dict, prompt="", guidance_scale=7.5, steps=20, strength=1.0, schedul
32
  init_image = dict["image"].convert("RGB").resize((1024, 1024))
33
  mask = dict["mask"].convert("RGB").resize((1024, 1024))
34
 
35
- output = pipe(prompt = prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
36
 
37
  return output.images[0], gr.update(visible=True)
38
 
@@ -89,8 +89,8 @@ with image_blocks as demo:
89
  with gr.Row(mobile_collapse=False, equal_height=True):
90
  guidance_scale = gr.Number(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
91
  steps = gr.Number(value=20, minimum=10, maximum=30, step=1, label="steps")
92
- strength = gr.Number(value=0.99, minimum=0.0, maximum=0.99, step=0.01, label="strength")
93
-
94
  with gr.Row(mobile_collapse=False, equal_height=True):
95
  schedulers = ["DEISMultistepScheduler", "HeunDiscreteScheduler", "EulerDiscreteScheduler", "DPMSolverMultistepScheduler", "DPMSolverMultistepScheduler-Karras", "DPMSolverMultistepScheduler-Karras-SDE"]
96
  scheduler = gr.Dropdown(label="Schedulers", choices=schedulers, value="EulerDiscreteScheduler")
@@ -103,7 +103,7 @@ with image_blocks as demo:
103
  share_button = gr.Button("Share to community", elem_id="share-btn",visible=True)
104
 
105
 
106
- btn.click(fn=predict, inputs=[image, prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
107
  share_button.click(None, [], [], _js=share_js)
108
 
109
  gr.Examples(
 
5
  import diffusers
6
  from share_btn import community_icon_html, loading_icon_html, share_js
7
 
8
+ device = "cuda" if torch.cuda.is_available() else "cpu"
9
+ pipe = AutoPipelineForInpainting.from_pretrained("diffusers/inpainting-sdxl-0.1", torch_dtype=torch.float16, variant="fp16").to(device)
10
 
11
  def read_content(file_path: str) -> str:
12
  """read the content of target file
 
16
 
17
  return content
18
 
19
+ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, strength=1.0, scheduler="EulerDiscreteScheduler"):
20
 
21
  scheduler_class_name = scheduler.split("-")[0]
22
 
 
32
  init_image = dict["image"].convert("RGB").resize((1024, 1024))
33
  mask = dict["mask"].convert("RGB").resize((1024, 1024))
34
 
35
+ 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)
36
 
37
  return output.images[0], gr.update(visible=True)
38
 
 
89
  with gr.Row(mobile_collapse=False, equal_height=True):
90
  guidance_scale = gr.Number(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
91
  steps = gr.Number(value=20, minimum=10, maximum=30, step=1, label="steps")
92
+ strength = gr.Number(value=0.99, minimum=0.01, maximum=0.99, step=0.01, label="strength")
93
+ negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt", info="what you don't want to see in the image")
94
  with gr.Row(mobile_collapse=False, equal_height=True):
95
  schedulers = ["DEISMultistepScheduler", "HeunDiscreteScheduler", "EulerDiscreteScheduler", "DPMSolverMultistepScheduler", "DPMSolverMultistepScheduler-Karras", "DPMSolverMultistepScheduler-Karras-SDE"]
96
  scheduler = gr.Dropdown(label="Schedulers", choices=schedulers, value="EulerDiscreteScheduler")
 
103
  share_button = gr.Button("Share to community", elem_id="share-btn",visible=True)
104
 
105
 
106
+ btn.click(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
107
  share_button.click(None, [], [], _js=share_js)
108
 
109
  gr.Examples(