Spaces:
Runtime error
Runtime error
Fabrice-TIERCELIN
commited on
Commit
•
97f85d2
1
Parent(s):
97505f8
Upload 3 files
Browse files- README.md +16 -6
- app.py +339 -162
- requirements.txt +6 -9
README.md
CHANGED
@@ -1,13 +1,23 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Inpaint SDXL (any size)
|
3 |
+
emoji: ↕️
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: purple
|
6 |
+
tags:
|
7 |
+
- Image-to-Image
|
8 |
+
- Image-2-Image
|
9 |
+
- Img-to-Img
|
10 |
+
- Img-2-Img
|
11 |
+
- SDXL
|
12 |
+
- Stable Diffusion
|
13 |
+
- language models
|
14 |
+
- LLMs
|
15 |
sdk: gradio
|
16 |
+
sdk_version: 3.41.2
|
17 |
app_file: app.py
|
18 |
pinned: false
|
19 |
license: mit
|
20 |
+
short_description: Modifies one detail of your image, at any resolution, freely
|
21 |
---
|
22 |
|
23 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,174 +1,351 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
#test
|
3 |
-
from io import BytesIO
|
4 |
-
import requests
|
5 |
-
import PIL
|
6 |
-
from PIL import Image
|
7 |
import numpy as np
|
8 |
-
import
|
9 |
-
import
|
|
|
|
|
10 |
import torch
|
11 |
-
from torch import autocast
|
12 |
-
import cv2
|
13 |
-
from matplotlib import pyplot as plt
|
14 |
-
from diffusers import DiffusionPipeline
|
15 |
-
from torchvision import transforms
|
16 |
-
from clipseg.models.clipseg import CLIPDensePredT
|
17 |
-
|
18 |
-
auth_token = os.environ.get("API_TOKEN") or True
|
19 |
|
20 |
-
|
21 |
-
response = requests.get(url)
|
22 |
-
return PIL.Image.open(BytesIO(response.content)).convert("RGB")
|
23 |
|
24 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
else:
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
cv2.cvtColor(bw_image, cv2.COLOR_BGR2RGB)
|
59 |
-
mask = Image.fromarray(np.uint8(bw_image)).convert('RGB')
|
60 |
-
os.remove(filename)
|
61 |
-
#with autocast("cuda"):
|
62 |
-
output = pipe(prompt = prompt, image=init_image, mask_image=mask, strength=0.8)
|
63 |
-
return output.images[0]
|
64 |
-
|
65 |
-
# examples = [[dict(image="init_image.png", mask="mask_image.png"), "A panda sitting on a bench"]]
|
66 |
-
css = '''
|
67 |
-
.container {max-width: 1150px;margin: auto;padding-top: 1.5rem}
|
68 |
-
#image_upload{min-height:400px}
|
69 |
-
#image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
|
70 |
-
#mask_radio .gr-form{background:transparent; border: none}
|
71 |
-
#word_mask{margin-top: .75em !important}
|
72 |
-
#word_mask textarea:disabled{opacity: 0.3}
|
73 |
-
.footer {margin-bottom: 45px;margin-top: 35px;text-align: center;border-bottom: 1px solid #e5e5e5}
|
74 |
-
.footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
|
75 |
-
.dark .footer {border-color: #303030}
|
76 |
-
.dark .footer>p {background: #0b0f19}
|
77 |
-
.acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
|
78 |
-
#image_upload .touch-none{display: flex}
|
79 |
-
'''
|
80 |
-
def swap_word_mask(radio_option):
|
81 |
-
if(radio_option == "type what to mask below"):
|
82 |
-
return gr.update(interactive=True, placeholder="A cat")
|
83 |
else:
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
"""
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
height="0.65em"
|
102 |
-
viewBox="0 0 115 115"
|
103 |
-
fill="none"
|
104 |
-
xmlns="http://www.w3.org/2000/svg"
|
105 |
-
>
|
106 |
-
<rect width="23" height="23" fill="white"></rect>
|
107 |
-
<rect y="69" width="23" height="23" fill="white"></rect>
|
108 |
-
<rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
|
109 |
-
<rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
110 |
-
<rect x="46" width="23" height="23" fill="white"></rect>
|
111 |
-
<rect x="46" y="69" width="23" height="23" fill="white"></rect>
|
112 |
-
<rect x="69" width="23" height="23" fill="black"></rect>
|
113 |
-
<rect x="69" y="69" width="23" height="23" fill="black"></rect>
|
114 |
-
<rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
|
115 |
-
<rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
116 |
-
<rect x="115" y="46" width="23" height="23" fill="white"></rect>
|
117 |
-
<rect x="115" y="115" width="23" height="23" fill="white"></rect>
|
118 |
-
<rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
119 |
-
<rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
|
120 |
-
<rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
121 |
-
<rect x="92" y="69" width="23" height="23" fill="white"></rect>
|
122 |
-
<rect x="69" y="46" width="23" height="23" fill="white"></rect>
|
123 |
-
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
124 |
-
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
125 |
-
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
126 |
-
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
127 |
-
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
128 |
-
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
129 |
-
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
130 |
-
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
131 |
-
</svg>
|
132 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
133 |
-
Stable Diffusion Multi Inpainting
|
134 |
-
</h1>
|
135 |
-
</div>
|
136 |
-
<p style="margin-bottom: 10px; font-size: 94%">
|
137 |
-
Inpaint Stable Diffusion by either drawing a mask or typing what to replace
|
138 |
-
</p>
|
139 |
-
</div>
|
140 |
"""
|
141 |
)
|
142 |
-
with gr.
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionXLInpaintPipeline
|
2 |
+
from PIL import Image, ImageFilter
|
3 |
+
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
5 |
import numpy as np
|
6 |
+
import time
|
7 |
+
import math
|
8 |
+
import random
|
9 |
+
import imageio
|
10 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
max_64_bit_int = 2**63 - 1
|
|
|
|
|
13 |
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
+
floatType = torch.float16 if torch.cuda.is_available() else torch.float32
|
16 |
+
variant = "fp16" if torch.cuda.is_available() else None
|
17 |
+
pipe = StableDiffusionXLInpaintPipeline.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype = floatType, variant = variant)
|
18 |
+
pipe = pipe.to(device)
|
19 |
+
|
20 |
+
def check(
|
21 |
+
source_img,
|
22 |
+
prompt,
|
23 |
+
uploaded_mask,
|
24 |
+
negative_prompt,
|
25 |
+
denoising_steps,
|
26 |
+
num_inference_steps,
|
27 |
+
guidance_scale,
|
28 |
+
image_guidance_scale,
|
29 |
+
strength,
|
30 |
+
randomize_seed,
|
31 |
+
seed,
|
32 |
+
debug_mode,
|
33 |
+
progress = gr.Progress()
|
34 |
+
):
|
35 |
+
if source_img is None:
|
36 |
+
raise gr.Error("Please provide an image.")
|
37 |
+
|
38 |
+
if prompt is None or prompt == "":
|
39 |
+
raise gr.Error("Please provide a prompt input.")
|
40 |
+
|
41 |
+
def inpaint(
|
42 |
+
source_img,
|
43 |
+
prompt,
|
44 |
+
uploaded_mask,
|
45 |
+
negative_prompt,
|
46 |
+
denoising_steps,
|
47 |
+
num_inference_steps,
|
48 |
+
guidance_scale,
|
49 |
+
image_guidance_scale,
|
50 |
+
strength,
|
51 |
+
randomize_seed,
|
52 |
+
seed,
|
53 |
+
debug_mode,
|
54 |
+
progress = gr.Progress()
|
55 |
+
):
|
56 |
+
check(
|
57 |
+
source_img,
|
58 |
+
prompt,
|
59 |
+
uploaded_mask,
|
60 |
+
negative_prompt,
|
61 |
+
denoising_steps,
|
62 |
+
num_inference_steps,
|
63 |
+
guidance_scale,
|
64 |
+
image_guidance_scale,
|
65 |
+
strength,
|
66 |
+
randomize_seed,
|
67 |
+
seed,
|
68 |
+
debug_mode
|
69 |
+
)
|
70 |
+
start = time.time()
|
71 |
+
progress(0, desc = "Preparing data...")
|
72 |
+
|
73 |
+
if negative_prompt is None:
|
74 |
+
negative_prompt = ""
|
75 |
+
|
76 |
+
if denoising_steps is None:
|
77 |
+
denoising_steps = 1000
|
78 |
+
|
79 |
+
if num_inference_steps is None:
|
80 |
+
num_inference_steps = 25
|
81 |
+
|
82 |
+
if guidance_scale is None:
|
83 |
+
guidance_scale = 7
|
84 |
+
|
85 |
+
if image_guidance_scale is None:
|
86 |
+
image_guidance_scale = 1.1
|
87 |
+
|
88 |
+
if strength is None:
|
89 |
+
strength = 0.99
|
90 |
+
|
91 |
+
if randomize_seed:
|
92 |
+
seed = random.randint(0, max_64_bit_int)
|
93 |
+
|
94 |
+
random.seed(seed)
|
95 |
+
#pipe = pipe.manual_seed(seed)
|
96 |
+
|
97 |
+
input_image = source_img["image"].convert("RGB")
|
98 |
+
|
99 |
+
original_height, original_width, original_channel = np.array(input_image).shape
|
100 |
+
output_width = original_width
|
101 |
+
output_height = original_height
|
102 |
+
|
103 |
+
if uploaded_mask is None:
|
104 |
+
mask_image = source_img["mask"].convert("RGB")
|
105 |
else:
|
106 |
+
mask_image = uploaded_mask.convert("RGB")
|
107 |
+
mask_image = mask_image.resize((original_width, original_height))
|
108 |
+
|
109 |
+
# Limited to 1 million pixels
|
110 |
+
if 1024 * 1024 < output_width * output_height:
|
111 |
+
factor = ((1024 * 1024) / (output_width * output_height))**0.5
|
112 |
+
process_width = math.floor(output_width * factor)
|
113 |
+
process_height = math.floor(output_height * factor)
|
114 |
+
|
115 |
+
limitation = " Due to technical limitation, the image have been downscaled and then upscaled.";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
else:
|
117 |
+
process_width = output_width
|
118 |
+
process_height = output_height
|
119 |
+
|
120 |
+
limitation = "";
|
121 |
+
|
122 |
+
# Width and height must be multiple of 8
|
123 |
+
if (process_width % 8) != 0 or (process_height % 8) != 0:
|
124 |
+
if ((process_width - (process_width % 8) + 8) * (process_height - (process_height % 8) + 8)) <= (1024 * 1024):
|
125 |
+
process_width = process_width - (process_width % 8) + 8
|
126 |
+
process_height = process_height - (process_height % 8) + 8
|
127 |
+
elif (process_height % 8) <= (process_width % 8) and ((process_width - (process_width % 8) + 8) * process_height) <= (1024 * 1024):
|
128 |
+
process_width = process_width - (process_width % 8) + 8
|
129 |
+
process_height = process_height - (process_height % 8)
|
130 |
+
elif (process_width % 8) <= (process_height % 8) and (process_width * (process_height - (process_height % 8) + 8)) <= (1024 * 1024):
|
131 |
+
process_width = process_width - (process_width % 8)
|
132 |
+
process_height = process_height - (process_height % 8) + 8
|
133 |
+
else:
|
134 |
+
process_width = process_width - (process_width % 8)
|
135 |
+
process_height = process_height - (process_height % 8)
|
136 |
+
|
137 |
+
progress(None, desc = "Processing...")
|
138 |
+
output_image = pipe(
|
139 |
+
seeds = [seed],
|
140 |
+
width = process_width,
|
141 |
+
height = process_height,
|
142 |
+
prompt = prompt,
|
143 |
+
negative_prompt = negative_prompt,
|
144 |
+
image = input_image,
|
145 |
+
mask_image = mask_image,
|
146 |
+
num_inference_steps = num_inference_steps,
|
147 |
+
guidance_scale = guidance_scale,
|
148 |
+
image_guidance_scale = image_guidance_scale,
|
149 |
+
strength = strength,
|
150 |
+
denoising_steps = denoising_steps,
|
151 |
+
show_progress_bar = True
|
152 |
+
).images[0]
|
153 |
|
154 |
+
if limitation != "":
|
155 |
+
output_image = output_image.resize((output_width, output_height))
|
156 |
+
|
157 |
+
if debug_mode == False:
|
158 |
+
input_image = None
|
159 |
+
mask_image = None
|
160 |
+
|
161 |
+
end = time.time()
|
162 |
+
secondes = int(end - start)
|
163 |
+
minutes = secondes // 60
|
164 |
+
secondes = secondes - (minutes * 60)
|
165 |
+
hours = minutes // 60
|
166 |
+
minutes = minutes - (hours * 60)
|
167 |
+
return [
|
168 |
+
output_image,
|
169 |
+
"Start again to get a different result. The new image is " + str(output_width) + " pixels large and " + str(output_height) + " pixels high, so an image of " + f'{output_width * output_height:,}' + " pixels. The image have been generated in " + str(hours) + " h, " + str(minutes) + " min, " + str(secondes) + " sec." + limitation,
|
170 |
+
input_image,
|
171 |
+
mask_image
|
172 |
+
]
|
173 |
+
|
174 |
+
def toggle_debug(is_debug_mode):
|
175 |
+
if is_debug_mode:
|
176 |
+
return [gr.update(visible = True)] * 2
|
177 |
+
else:
|
178 |
+
return [gr.update(visible = False)] * 2
|
179 |
+
|
180 |
+
with gr.Blocks() as interface:
|
181 |
+
gr.Markdown(
|
182 |
"""
|
183 |
+
<p style="text-align: center;"><b><big><big><big>Inpaint</big></big></big></b></p>
|
184 |
+
<p style="text-align: center;">Modifies one detail of your image, at any resolution, freely, without account, without watermark, without installation, which can be downloaded</p>
|
185 |
+
<br/>
|
186 |
+
<br/>
|
187 |
+
🚀 Powered by <i>SDXL 1.0</i> artificial intellingence.
|
188 |
+
<br/>
|
189 |
+
🐌 Slow process... ~1 hour.<br>You can duplicate this space on a free account, it works on CPU and should also run on CUDA.<br/>
|
190 |
+
<a href='https://huggingface.co/spaces/multimodalart/stable-diffusion-inpainting?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14'></a>
|
191 |
+
<br/>
|
192 |
+
⚖️ You can use, modify and share the generated images but not for commercial uses.
|
193 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
"""
|
195 |
)
|
196 |
+
with gr.Column():
|
197 |
+
source_img = gr.Image(label = "Your image", source = "upload", tool = "sketch", type = "pil")
|
198 |
+
prompt = gr.Textbox(label = "Prompt", info = "Describe the subject, the background and the style of image; 77 token limit", placeholder = "Describe what you want to see in the entire image")
|
199 |
+
with gr.Accordion("Upload a mask", open = False):
|
200 |
+
uploaded_mask = gr.Image(label = "Already made mask (black pixels will be preserved, white pixels will be redrawn)", source = "upload", type = "pil")
|
201 |
+
with gr.Accordion("Advanced options", open = False):
|
202 |
+
negative_prompt = gr.Textbox(label = "Negative prompt", placeholder = "Describe what you do NOT want to see in the entire image", value = "Ugly, malformed, noise, blur, watermark")
|
203 |
+
denoising_steps = gr.Slider(minimum = 0, maximum = 1000, value = 1000, step = 1, label = "Denoising", info = "lower=irrelevant result, higher=relevant result")
|
204 |
+
num_inference_steps = gr.Slider(minimum = 10, maximum = 100, value = 25, step = 1, label = "Number of inference steps", info = "lower=faster, higher=image quality")
|
205 |
+
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")
|
206 |
+
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")
|
207 |
+
strength = gr.Number(value = 0.99, minimum = 0.01, maximum = 1.0, step = 0.01, label = "Strength", info = "lower=follow the original area, higher=redraw from scratch")
|
208 |
+
randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed (not working, always checked)", value = True, info = "If checked, result is always different")
|
209 |
+
seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed (if not randomized)")
|
210 |
+
debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
|
211 |
+
|
212 |
+
submit = gr.Button("Inpaint", variant = "primary")
|
213 |
+
|
214 |
+
inpainted_image = gr.Image(label = "Inpainted image")
|
215 |
+
information = gr.Label(label = "Information")
|
216 |
+
original_image = gr.Image(label = "Original image", visible = False)
|
217 |
+
mask_image = gr.Image(label = "Mask image", visible = False)
|
218 |
+
|
219 |
+
submit.click(toggle_debug, debug_mode, [
|
220 |
+
original_image,
|
221 |
+
mask_image
|
222 |
+
], queue = False, show_progress = False).then(check, inputs = [
|
223 |
+
source_img,
|
224 |
+
prompt,
|
225 |
+
uploaded_mask,
|
226 |
+
negative_prompt,
|
227 |
+
denoising_steps,
|
228 |
+
num_inference_steps,
|
229 |
+
guidance_scale,
|
230 |
+
image_guidance_scale,
|
231 |
+
strength,
|
232 |
+
randomize_seed,
|
233 |
+
seed,
|
234 |
+
debug_mode
|
235 |
+
], outputs = [], queue = False, show_progress = False).success(inpaint, inputs = [
|
236 |
+
source_img,
|
237 |
+
prompt,
|
238 |
+
uploaded_mask,
|
239 |
+
negative_prompt,
|
240 |
+
denoising_steps,
|
241 |
+
num_inference_steps,
|
242 |
+
guidance_scale,
|
243 |
+
image_guidance_scale,
|
244 |
+
strength,
|
245 |
+
randomize_seed,
|
246 |
+
seed,
|
247 |
+
debug_mode
|
248 |
+
], outputs = [
|
249 |
+
inpainted_image,
|
250 |
+
information,
|
251 |
+
original_image,
|
252 |
+
mask_image
|
253 |
+
], scroll_to_output = True)
|
254 |
+
|
255 |
+
gr.Examples(
|
256 |
+
inputs = [
|
257 |
+
source_img,
|
258 |
+
prompt,
|
259 |
+
uploaded_mask,
|
260 |
+
negative_prompt,
|
261 |
+
denoising_steps,
|
262 |
+
num_inference_steps,
|
263 |
+
guidance_scale,
|
264 |
+
image_guidance_scale,
|
265 |
+
strength,
|
266 |
+
randomize_seed,
|
267 |
+
seed,
|
268 |
+
debug_mode
|
269 |
+
],
|
270 |
+
outputs = [
|
271 |
+
inpainted_image,
|
272 |
+
information,
|
273 |
+
original_image,
|
274 |
+
mask_image
|
275 |
+
],
|
276 |
+
examples = [
|
277 |
+
[
|
278 |
+
"./Examples/Example1.png",
|
279 |
+
"A deer, in a forest landscape, ultrarealistic, realistic, photorealistic, 8k",
|
280 |
+
"./Examples/Mask1.webp",
|
281 |
+
"Painting, drawing, cartoon, ugly, malformed, noise, blur, watermark",
|
282 |
+
1000,
|
283 |
+
25,
|
284 |
+
7,
|
285 |
+
1.1,
|
286 |
+
0.99,
|
287 |
+
True,
|
288 |
+
42,
|
289 |
+
False
|
290 |
+
],
|
291 |
+
[
|
292 |
+
"./Examples/Example3.jpg",
|
293 |
+
"An angry old woman, ultrarealistic, realistic, photorealistic, 8k",
|
294 |
+
"./Examples/Mask3.gif",
|
295 |
+
"Painting, drawing, cartoon, ugly, malformed, noise, blur, watermark",
|
296 |
+
1000,
|
297 |
+
25,
|
298 |
+
7,
|
299 |
+
1.5,
|
300 |
+
0.99,
|
301 |
+
True,
|
302 |
+
42,
|
303 |
+
False
|
304 |
+
],
|
305 |
+
[
|
306 |
+
"./Examples/Example4.gif",
|
307 |
+
"A laptop, ultrarealistic, realistic, photorealistic, 8k",
|
308 |
+
"./Examples/Mask4.bmp",
|
309 |
+
"Painting, drawing, cartoon, ugly, malformed, noise, blur, watermark",
|
310 |
+
1000,
|
311 |
+
25,
|
312 |
+
7,
|
313 |
+
1.1,
|
314 |
+
0.99,
|
315 |
+
True,
|
316 |
+
42,
|
317 |
+
False
|
318 |
+
],
|
319 |
+
[
|
320 |
+
"./Examples/Example5.bmp",
|
321 |
+
"A sand castle, ultrarealistic, realistic, photorealistic, 8k",
|
322 |
+
"./Examples/Mask5.png",
|
323 |
+
"Painting, drawing, cartoon, ugly, malformed, noise, blur, watermark",
|
324 |
+
1000,
|
325 |
+
50,
|
326 |
+
7,
|
327 |
+
1.5,
|
328 |
+
0.5,
|
329 |
+
True,
|
330 |
+
42,
|
331 |
+
False
|
332 |
+
],
|
333 |
+
[
|
334 |
+
"./Examples/Example2.webp",
|
335 |
+
"A cat, ultrarealistic, realistic, photorealistic, 8k",
|
336 |
+
"./Examples/Mask2.png",
|
337 |
+
"Painting, drawing, cartoon, ugly, malformed, noise, blur, watermark",
|
338 |
+
1000,
|
339 |
+
25,
|
340 |
+
7,
|
341 |
+
1.1,
|
342 |
+
0.99,
|
343 |
+
True,
|
344 |
+
42,
|
345 |
+
False
|
346 |
+
],
|
347 |
+
],
|
348 |
+
cache_examples = False,
|
349 |
+
)
|
350 |
+
|
351 |
+
interface.queue().launch()
|
requirements.txt
CHANGED
@@ -1,11 +1,8 @@
|
|
1 |
-
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
-
torch
|
3 |
torchvision
|
4 |
-
diffusers
|
5 |
-
transformers
|
|
|
6 |
ftfy
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
opencv-python
|
11 |
-
git+https://github.com/openai/CLIP.git
|
|
|
|
|
|
|
1 |
torchvision
|
2 |
+
diffusers
|
3 |
+
transformers
|
4 |
+
accelerate
|
5 |
ftfy
|
6 |
+
scipy
|
7 |
+
imageio
|
8 |
+
invisible_watermark
|
|
|
|