KingNish commited on
Commit
3b1667a
1 Parent(s): 19ec5a1

Customizable fill

Browse files

This help use to select what they want to fill as option.

Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -44,17 +44,9 @@ pipe = StableDiffusionXLFillPipeline.from_pretrained(
44
 
45
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
46
 
47
- prompt = "high quality"
48
- (
49
- prompt_embeds,
50
- negative_prompt_embeds,
51
- pooled_prompt_embeds,
52
- negative_pooled_prompt_embeds,
53
- ) = pipe.encode_prompt(prompt, "cuda", True)
54
-
55
 
56
  @spaces.GPU
57
- def fill_image(image, model_selection):
58
  source = image["background"]
59
  mask = image["layers"][0]
60
 
@@ -62,6 +54,14 @@ def fill_image(image, model_selection):
62
  binary_mask = alpha_channel.point(lambda p: p > 0 and 255)
63
  cnet_image = source.copy()
64
  cnet_image.paste(0, (0, 0), binary_mask)
 
 
 
 
 
 
 
 
65
 
66
  for image in pipe(
67
  prompt_embeds=prompt_embeds,
@@ -119,15 +119,18 @@ with gr.Blocks(css=css) as demo:
119
  label="Model",
120
  )
121
 
 
 
 
122
  run_button.click(
123
  fn=clear_result,
124
  inputs=None,
125
  outputs=result,
126
  ).then(
127
  fn=fill_image,
128
- inputs=[input_image, model_selection],
129
  outputs=result,
130
  )
131
 
132
 
133
- demo.launch(share=False)
 
44
 
45
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
46
 
 
 
 
 
 
 
 
 
47
 
48
  @spaces.GPU
49
+ def fill_image(image, model_selection, prompt_text):
50
  source = image["background"]
51
  mask = image["layers"][0]
52
 
 
54
  binary_mask = alpha_channel.point(lambda p: p > 0 and 255)
55
  cnet_image = source.copy()
56
  cnet_image.paste(0, (0, 0), binary_mask)
57
+
58
+ prompt = f"high quality, {prompt_text}"
59
+ (
60
+ prompt_embeds,
61
+ negative_prompt_embeds,
62
+ pooled_prompt_embeds,
63
+ negative_pooled_prompt_embeds,
64
+ ) = pipe.encode_prompt(prompt, "cuda", True)
65
 
66
  for image in pipe(
67
  prompt_embeds=prompt_embeds,
 
119
  label="Model",
120
  )
121
 
122
+ with gr.Row():
123
+ prompt_input = gr.Textbox(label="Prompt (Optional)")
124
+
125
  run_button.click(
126
  fn=clear_result,
127
  inputs=None,
128
  outputs=result,
129
  ).then(
130
  fn=fill_image,
131
+ inputs=[input_image, model_selection, prompt_input],
132
  outputs=result,
133
  )
134
 
135
 
136
+ demo.launch(share=False)