Fabrice-TIERCELIN commited on
Commit
a92c6b1
1 Parent(s): 0143c38

This PR allows to set the Number of inference steps

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -49,7 +49,7 @@ def clear_all():
49
  return gr.update(value=None), gr.update(value=None), gr.update(value=[], visible=False), gr.update(visible=False), gr.update(visible=False)
50
 
51
  @spaces.GPU()
52
- def generate(image_editor, prompt, neg_prompt, versions):
53
  start = time.time()
54
  image = image_editor['background'].convert('RGB')
55
 
@@ -73,7 +73,8 @@ def generate(image_editor, prompt, neg_prompt, versions):
73
  pipeline.to("cuda")
74
  final_image = pipeline(prompt=prompt,
75
  image=image,
76
- mask_image=mask).images[0]
 
77
 
78
 
79
  # Make sure the longest side of image is 1024
@@ -112,9 +113,10 @@ with gr.Blocks() as demo:
112
  with gr.Column():
113
  sketch_pad = gr.ImageMask(type='pil', label='Inpaint')
114
  prompt = gr.Textbox(label="Prompt")
115
- generate_button = gr.Button("Generate")
116
  with gr.Accordion("Advanced Settings", open=False):
117
  neg_prompt = gr.Textbox(label='Negative Prompt', value='ugly, deformed')
 
118
  with gr.Column():
119
  version_gallery = gr.Gallery(label="Versions", type="pil", object_fit='contain', visible=False)
120
  restore_button = gr.Button("Restore Version", visible=False)
@@ -130,7 +132,7 @@ with gr.Blocks() as demo:
130
  # )
131
 
132
  version_gallery.select(get_select_index, None, selected)
133
- generate_button.click(fn=generate, inputs=[sketch_pad,prompt, neg_prompt, version_gallery], outputs=[sketch_pad, version_gallery, restore_button, clear_button])
134
  restore_button.click(fn=restore_version, inputs=[selected, version_gallery], outputs=sketch_pad)
135
  clear_button.click(clear_all, inputs=None, outputs=[sketch_pad, prompt, version_gallery, restore_button, clear_button])
136
 
 
49
  return gr.update(value=None), gr.update(value=None), gr.update(value=[], visible=False), gr.update(visible=False), gr.update(visible=False)
50
 
51
  @spaces.GPU()
52
+ def generate(image_editor, prompt, neg_prompt, versions, num_inference_steps):
53
  start = time.time()
54
  image = image_editor['background'].convert('RGB')
55
 
 
73
  pipeline.to("cuda")
74
  final_image = pipeline(prompt=prompt,
75
  image=image,
76
+ mask_image=mask,
77
+ num_inference_steps=num_inference_steps).images[0]
78
 
79
 
80
  # Make sure the longest side of image is 1024
 
113
  with gr.Column():
114
  sketch_pad = gr.ImageMask(type='pil', label='Inpaint')
115
  prompt = gr.Textbox(label="Prompt")
116
+ generate_button = gr.Button(value="Inpaint", variant="primary")
117
  with gr.Accordion("Advanced Settings", open=False):
118
  neg_prompt = gr.Textbox(label='Negative Prompt', value='ugly, deformed')
119
+ num_inference_steps = gr.Slider(minimum = 10, maximum = 100, value = 30, step = 1, label = "Number of inference steps", info = "lower=faster, higher=image quality")
120
  with gr.Column():
121
  version_gallery = gr.Gallery(label="Versions", type="pil", object_fit='contain', visible=False)
122
  restore_button = gr.Button("Restore Version", visible=False)
 
132
  # )
133
 
134
  version_gallery.select(get_select_index, None, selected)
135
+ generate_button.click(fn=generate, inputs=[sketch_pad,prompt, neg_prompt, version_gallery, num_inference_steps], outputs=[sketch_pad, version_gallery, restore_button, clear_button])
136
  restore_button.click(fn=restore_version, inputs=[selected, version_gallery], outputs=sketch_pad)
137
  clear_button.click(clear_all, inputs=None, outputs=[sketch_pad, prompt, version_gallery, restore_button, clear_button])
138