Spaces:
Runtime error
Runtime error
Commit
•
497aa6f
1
Parent(s):
e5632e8
mask
Browse files- app.py +8 -8
- example1_mask.png +0 -0
app.py
CHANGED
@@ -70,8 +70,8 @@ def image_inpainting(prompt, image_path, mask_image_path, num_samples=4, is_orig
|
|
70 |
guidance_scale = 7.5
|
71 |
generator = torch.Generator(device=device).manual_seed(0) # change the seed to get different results
|
72 |
|
73 |
-
images = pipe(prompt=prompt, image=image, mask_image=mask_image, guidance_scale=guidance_scale,
|
74 |
-
num_images_per_prompt=num_samples).images
|
75 |
else:
|
76 |
images = pipe(prompt=prompt, image=image, mask_image=mask_image, num_images_per_prompt=num_samples).images
|
77 |
|
@@ -83,9 +83,8 @@ def image_inpainting(prompt, image_path, mask_image_path, num_samples=4, is_orig
|
|
83 |
title = "Person Matting & Stable Diffusion In-Painting"
|
84 |
description = "Inpainting Stable Diffusion <br/><b>mediapipe + Stable Diffusion<b/><br/>"
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
[os.path.join(os.path.dirname(__file__), 'example1.png'), 'a bench in a field', 2],
|
89 |
# [os.path.join(os.path.dirname(__file__), "example2.png"), 'a building with many steps', 2],
|
90 |
# [os.path.join(os.path.dirname(__file__), "example3.png"), 'a big ship parked on the shore', 2]
|
91 |
]
|
@@ -95,7 +94,8 @@ def predict1(dict, prompt, num_samples):
|
|
95 |
dict['image'].save('image.png')
|
96 |
# dict['mask'].save('mask.png')
|
97 |
mediapipe_segmentation('image.png', 'm_mask.png')
|
98 |
-
image = image_inpainting(prompt, num_samples=num_samples, image_path='image.png', mask_image_path='m_mask.png',
|
|
|
99 |
return image
|
100 |
|
101 |
|
@@ -103,7 +103,8 @@ def predict2(dict, prompt, num_samples):
|
|
103 |
dict['image'].save('image.png')
|
104 |
if 'mask' in dict:
|
105 |
dict['mask'].save('mask.png')
|
106 |
-
image = image_inpainting(prompt, num_samples=num_samples, image_path='image.png', mask_image_path='mask.png',
|
|
|
107 |
return image
|
108 |
|
109 |
|
@@ -115,6 +116,5 @@ greeter_1 = gr.Interface(predict1, inputs=[image_input, prompt, number], outputs
|
|
115 |
greeter_2 = gr.Interface(predict2, inputs=[image_input, prompt, number], outputs=gr.Image(label='paint'))
|
116 |
demo = gr.Parallel(greeter_1, greeter_2, examples=examples)
|
117 |
|
118 |
-
|
119 |
if __name__ == "__main__":
|
120 |
demo.launch(enable_queue=True)
|
|
|
70 |
guidance_scale = 7.5
|
71 |
generator = torch.Generator(device=device).manual_seed(0) # change the seed to get different results
|
72 |
|
73 |
+
images = pipe(prompt=prompt, image=image, mask_image=mask_image, guidance_scale=guidance_scale,
|
74 |
+
generator=generator, num_images_per_prompt=num_samples).images
|
75 |
else:
|
76 |
images = pipe(prompt=prompt, image=image, mask_image=mask_image, num_images_per_prompt=num_samples).images
|
77 |
|
|
|
83 |
title = "Person Matting & Stable Diffusion In-Painting"
|
84 |
description = "Inpainting Stable Diffusion <br/><b>mediapipe + Stable Diffusion<b/><br/>"
|
85 |
|
86 |
+
examples = [[{'image': os.path.join(os.path.dirname(__file__), 'example1.png'),
|
87 |
+
'mask': os.path.join(os.path.dirname(__file__), 'example1_mask.png')}, 'a bench in a field', 2],
|
|
|
88 |
# [os.path.join(os.path.dirname(__file__), "example2.png"), 'a building with many steps', 2],
|
89 |
# [os.path.join(os.path.dirname(__file__), "example3.png"), 'a big ship parked on the shore', 2]
|
90 |
]
|
|
|
94 |
dict['image'].save('image.png')
|
95 |
# dict['mask'].save('mask.png')
|
96 |
mediapipe_segmentation('image.png', 'm_mask.png')
|
97 |
+
image = image_inpainting(prompt, num_samples=num_samples, image_path='image.png', mask_image_path='m_mask.png',
|
98 |
+
is_origin=False)
|
99 |
return image
|
100 |
|
101 |
|
|
|
103 |
dict['image'].save('image.png')
|
104 |
if 'mask' in dict:
|
105 |
dict['mask'].save('mask.png')
|
106 |
+
image = image_inpainting(prompt, num_samples=num_samples, image_path='image.png', mask_image_path='mask.png',
|
107 |
+
is_origin=True)
|
108 |
return image
|
109 |
|
110 |
|
|
|
116 |
greeter_2 = gr.Interface(predict2, inputs=[image_input, prompt, number], outputs=gr.Image(label='paint'))
|
117 |
demo = gr.Parallel(greeter_1, greeter_2, examples=examples)
|
118 |
|
|
|
119 |
if __name__ == "__main__":
|
120 |
demo.launch(enable_queue=True)
|
example1_mask.png
ADDED
![]() |