Fabrice-TIERCELIN
commited on
Commit
•
9f655e4
1
Parent(s):
77f493d
This PR adds a new parameter: Classifier-Free Guidance Scale
Browse files
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):
|
53 |
start = time.time()
|
54 |
image = image_editor['background'].convert('RGB')
|
55 |
|
@@ -74,7 +74,8 @@ def generate(image_editor, prompt, neg_prompt, versions, num_inference_steps):
|
|
74 |
final_image = pipeline(prompt=prompt,
|
75 |
image=image,
|
76 |
mask_image=mask,
|
77 |
-
num_inference_steps=num_inference_steps
|
|
|
78 |
|
79 |
|
80 |
# Make sure the longest side of image is 1024
|
@@ -117,6 +118,7 @@ with gr.Blocks() as demo:
|
|
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,7 +134,7 @@ with gr.Blocks() as demo:
|
|
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 |
|
|
|
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 |
|
|
|
74 |
final_image = pipeline(prompt=prompt,
|
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
|
|
|
118 |
with gr.Accordion("Advanced Settings", open=False):
|
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 |
# )
|
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 |
|