Fabrice-TIERCELIN commited on
Commit
f3ba39a
1 Parent(s): 8ed26b3

This PR adds the Image Guidance Scale

Browse files
Files changed (1) hide show
  1. app.py +5 -3
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, num_inference_steps, guidance_scale):
53
  start = time.time()
54
  image = image_editor['background'].convert('RGB')
55
 
@@ -75,7 +75,8 @@ def generate(image_editor, prompt, neg_prompt, versions, num_inference_steps, gu
75
  image=image,
76
  mask_image=mask,
77
  num_inference_steps=num_inference_steps,
78
- guidance_scale=guidance_scale).images[0]
 
79
 
80
 
81
  # Make sure the longest side of image is 1024
@@ -119,6 +120,7 @@ with gr.Blocks() as demo:
119
  neg_prompt = gr.Textbox(label='Negative Prompt', value='ugly, deformed')
120
  num_inference_steps = gr.Slider(minimum = 10, maximum = 100, value = 30, step = 1, label = "Number of inference steps", info = "lower=faster, higher=image quality")
121
  guidance_scale = gr.Slider(minimum = 1, maximum = 13, value = 7, step = 0.1, label = "Classifier-Free Guidance Scale", info = "lower=image quality, higher=follow the prompt")
 
122
  with gr.Column():
123
  version_gallery = gr.Gallery(label="Versions", type="pil", object_fit='contain', visible=False)
124
  restore_button = gr.Button("Restore Version", visible=False)
@@ -134,7 +136,7 @@ with gr.Blocks() as demo:
134
  # )
135
 
136
  version_gallery.select(get_select_index, None, selected)
137
- generate_button.click(fn=generate, inputs=[sketch_pad,prompt, neg_prompt, version_gallery, num_inference_steps, guidance_scale], outputs=[sketch_pad, version_gallery, restore_button, clear_button])
138
  restore_button.click(fn=restore_version, inputs=[selected, version_gallery], outputs=sketch_pad)
139
  clear_button.click(clear_all, inputs=None, outputs=[sketch_pad, prompt, version_gallery, restore_button, clear_button])
140
 
 
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, guidance_scale, image_guidance_scale):
53
  start = time.time()
54
  image = image_editor['background'].convert('RGB')
55
 
 
75
  image=image,
76
  mask_image=mask,
77
  num_inference_steps=num_inference_steps,
78
+ guidance_scale=guidance_scale,
79
+ image_guidance_scale=image_guidance_scale).images[0]
80
 
81
 
82
  # Make sure the longest side of image is 1024
 
120
  neg_prompt = gr.Textbox(label='Negative Prompt', value='ugly, deformed')
121
  num_inference_steps = gr.Slider(minimum = 10, maximum = 100, value = 30, step = 1, label = "Number of inference steps", info = "lower=faster, higher=image quality")
122
  guidance_scale = gr.Slider(minimum = 1, maximum = 13, value = 7, step = 0.1, label = "Classifier-Free Guidance Scale", info = "lower=image quality, higher=follow the prompt")
123
+ image_guidance_scale = gr.Slider(minimum = 1, value = 1.1, step = 0.1, label = "Image Guidance Scale", info = "lower=image quality, higher=follow the image")
124
  with gr.Column():
125
  version_gallery = gr.Gallery(label="Versions", type="pil", object_fit='contain', visible=False)
126
  restore_button = gr.Button("Restore Version", visible=False)
 
136
  # )
137
 
138
  version_gallery.select(get_select_index, None, selected)
139
+ generate_button.click(fn=generate, inputs=[sketch_pad,prompt, neg_prompt, version_gallery, num_inference_steps, guidance_scale, image_guidance_scale], outputs=[sketch_pad, version_gallery, restore_button, clear_button])
140
  restore_button.click(fn=restore_version, inputs=[selected, version_gallery], outputs=sketch_pad)
141
  clear_button.click(clear_all, inputs=None, outputs=[sketch_pad, prompt, version_gallery, restore_button, clear_button])
142