-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinpaint.py
64 lines (56 loc) · 3 KB
/
inpaint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import gradio as gr
from stable_diffusion.stable_diffusion import StableDiffusion
def inference_fn(prompt, negative_prompt, num_inference_steps, guidance_scale, seed, reference_image, denoise_strength,
inpaint_mask, mask_feathering_strength):
global SD_INSTANCE
output = SD_INSTANCE.inpaint(
prompt=prompt,
negative_prompt=negative_prompt,
num_steps=num_inference_steps,
unconditional_guidance_scale=guidance_scale,
reference_image=reference_image,
reference_image_strength=denoise_strength,
seed=None if seed == -1 else seed,
inpaint_mask=inpaint_mask,
mask_blur_strength=mask_feathering_strength,
)
return output[0]
def main():
height = 512
width = 512
global SD_INSTANCE
SD_INSTANCE = StableDiffusion(img_height=height, img_width=width, jit_compile=True)
with gr.Blocks() as app:
with gr.Tab("Inpaint"):
with gr.Row():
with gr.Column():
gr.Markdown("Text Encoder")
prompt = gr.Textbox(label="prompt", value="hello stable diffusion")
negative_prompt = gr.Textbox(label="negative prompt", value="")
gr.Markdown("Sampler")
num_inference_steps = gr.Slider(label="steps", value=25, minimum=1, maximum=100, step=1,
interactive=True)
guidance_scale = gr.Slider(label="guidance scale", value=7.0, minimum=0.0, maximum=100.0, step=0.01,
interactive=True)
seed = gr.Number(label='seed', value=-1, min_width=100, precision=0)
gr.Markdown("Image 2 Image")
denoise_strength = gr.Slider(label="denoise strength", value=0.8, minimum=0.0, maximum=1.0,
step=0.01,
interactive=True)
gr.Markdown("Inpaint")
mask_feathering_strength = gr.Slider(label="mask feathering strength", value=5, minimum=1,
maximum=256, step=1,
interactive=True)
with gr.Row():
reference_image = gr.Image(width=width, height=height, label="Image 2 Image")
inpaint_mask = gr.Image(width=width, height=height, label="Inpaint Mask")
output_image = gr.Image(width=width, height=height)
inference_button = gr.Button("inference")
inference_button.click(fn=inference_fn,
inputs=[prompt, negative_prompt, num_inference_steps,
guidance_scale, seed, reference_image, denoise_strength, inpaint_mask,
mask_feathering_strength],
outputs=output_image)
app.launch()
if __name__ == '__main__':
main()