Spaces:
Runtime error
Runtime error
Upload 8 files
Browse files- .gitattributes +3 -0
- README.md +10 -17
- app.py +174 -1058
- cat.png +3 -0
- flowers.png +3 -0
- monster.png +3 -0
- optimization.py +60 -0
- optimization_utils.py +96 -0
- requirements.txt +5 -43
.gitattributes
CHANGED
|
@@ -61,3 +61,6 @@ img_examples/Example5.png filter=lfs diff=lfs merge=lfs -text
|
|
| 61 |
img_examples/Example6.png filter=lfs diff=lfs merge=lfs -text
|
| 62 |
Example1.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 63 |
RealESRGAN_examples/Example1.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
img_examples/Example6.png filter=lfs diff=lfs merge=lfs -text
|
| 62 |
Example1.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 63 |
RealESRGAN_examples/Example1.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
cat.png filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
flowers.png filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
monster.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,21 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
|
|
|
|
|
|
|
|
|
| 3 |
sdk: gradio
|
| 4 |
-
|
| 5 |
-
sdk_version: 5.29.1
|
| 6 |
app_file: app.py
|
|
|
|
| 7 |
license: mit
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
- Restoring
|
| 13 |
-
- Image-to-Image
|
| 14 |
-
- Image-2-Image
|
| 15 |
-
- Img-to-Img
|
| 16 |
-
- Img-2-Img
|
| 17 |
-
- language models
|
| 18 |
-
- LLMs
|
| 19 |
-
short_description: Restore blurred or small images with prompt
|
| 20 |
-
suggested_hardware: zero-a10g
|
| 21 |
-
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: FLUX.1 Kontext
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.34.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
license: mit
|
| 11 |
+
short_description: 'Kontext image editing on FLUX[dev] '
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,1058 +1,174 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
import
|
| 7 |
-
import
|
| 8 |
-
import
|
| 9 |
-
import
|
| 10 |
-
import random
|
| 11 |
-
from
|
| 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 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
if
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
"
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 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 |
-
|
| 175 |
-
if str(e).startswith("No GPU is currently available for you after 60s"):
|
| 176 |
-
print('Exception identified!!!')
|
| 177 |
-
#if str(type(e)) == "<class 'gradio.exceptions.Error'>":
|
| 178 |
-
#print('Exception of name ' + type(e).__name__)
|
| 179 |
-
raise e
|
| 180 |
-
|
| 181 |
-
def restore_in_Xmin(
|
| 182 |
-
noisy_image,
|
| 183 |
-
rotation,
|
| 184 |
-
denoise_image,
|
| 185 |
-
prompt,
|
| 186 |
-
a_prompt,
|
| 187 |
-
n_prompt,
|
| 188 |
-
num_samples,
|
| 189 |
-
min_size,
|
| 190 |
-
downscale,
|
| 191 |
-
upscale,
|
| 192 |
-
edm_steps,
|
| 193 |
-
s_stage1,
|
| 194 |
-
s_stage2,
|
| 195 |
-
s_cfg,
|
| 196 |
-
randomize_seed,
|
| 197 |
-
seed,
|
| 198 |
-
s_churn,
|
| 199 |
-
s_noise,
|
| 200 |
-
color_fix_type,
|
| 201 |
-
diff_dtype,
|
| 202 |
-
ae_dtype,
|
| 203 |
-
gamma_correction,
|
| 204 |
-
linear_CFG,
|
| 205 |
-
spt_linear_CFG,
|
| 206 |
-
linear_s_stage2,
|
| 207 |
-
spt_linear_s_stage2,
|
| 208 |
-
model_select,
|
| 209 |
-
output_format,
|
| 210 |
-
allocation
|
| 211 |
-
):
|
| 212 |
-
print("noisy_image:\n" + str(noisy_image))
|
| 213 |
-
print("denoise_image:\n" + str(denoise_image))
|
| 214 |
-
print("rotation: " + str(rotation))
|
| 215 |
-
print("prompt: " + str(prompt))
|
| 216 |
-
print("a_prompt: " + str(a_prompt))
|
| 217 |
-
print("n_prompt: " + str(n_prompt))
|
| 218 |
-
print("num_samples: " + str(num_samples))
|
| 219 |
-
print("min_size: " + str(min_size))
|
| 220 |
-
print("downscale: " + str(downscale))
|
| 221 |
-
print("upscale: " + str(upscale))
|
| 222 |
-
print("edm_steps: " + str(edm_steps))
|
| 223 |
-
print("s_stage1: " + str(s_stage1))
|
| 224 |
-
print("s_stage2: " + str(s_stage2))
|
| 225 |
-
print("s_cfg: " + str(s_cfg))
|
| 226 |
-
print("randomize_seed: " + str(randomize_seed))
|
| 227 |
-
print("seed: " + str(seed))
|
| 228 |
-
print("s_churn: " + str(s_churn))
|
| 229 |
-
print("s_noise: " + str(s_noise))
|
| 230 |
-
print("color_fix_type: " + str(color_fix_type))
|
| 231 |
-
print("diff_dtype: " + str(diff_dtype))
|
| 232 |
-
print("ae_dtype: " + str(ae_dtype))
|
| 233 |
-
print("gamma_correction: " + str(gamma_correction))
|
| 234 |
-
print("linear_CFG: " + str(linear_CFG))
|
| 235 |
-
print("linear_s_stage2: " + str(linear_s_stage2))
|
| 236 |
-
print("spt_linear_CFG: " + str(spt_linear_CFG))
|
| 237 |
-
print("spt_linear_s_stage2: " + str(spt_linear_s_stage2))
|
| 238 |
-
print("model_select: " + str(model_select))
|
| 239 |
-
print("GPU time allocation: " + str(allocation) + " min")
|
| 240 |
-
print("output_format: " + str(output_format))
|
| 241 |
-
|
| 242 |
-
if input_image_debug_value[0] is not None or prompt_debug_value[0] is not None or upscale_debug_value[0] is not None:
|
| 243 |
-
denoise_image = noisy_image = input_image_debug_value[0]
|
| 244 |
-
a_prompt = prompt_debug_value[0]
|
| 245 |
-
upscale = upscale_debug_value[0]
|
| 246 |
-
allocation = min(allocation * 60 * 100, 600)
|
| 247 |
-
seed = random.randint(0, max_64_bit_int)
|
| 248 |
-
|
| 249 |
-
input_format = re.sub(r"^.*\.([^\.]+)$", r"\1", noisy_image)
|
| 250 |
-
|
| 251 |
-
if input_format not in ['png', 'webp', 'jpg', 'jpeg', 'gif', 'bmp', 'avif']:
|
| 252 |
-
gr.Warning('Invalid image format. Please first convert into *.png, *.webp, *.jpg, *.jpeg, *.gif, *.bmp, *.heic or *.avif.')
|
| 253 |
-
return None, None, None, None, None, gr.update(interactive = False)
|
| 254 |
-
|
| 255 |
-
if output_format == "input":
|
| 256 |
-
if noisy_image is None:
|
| 257 |
-
output_format = "png"
|
| 258 |
-
else:
|
| 259 |
-
output_format = input_format
|
| 260 |
-
print("final output_format: " + str(output_format))
|
| 261 |
-
|
| 262 |
-
if prompt is None:
|
| 263 |
-
prompt = ""
|
| 264 |
-
|
| 265 |
-
if a_prompt is None:
|
| 266 |
-
a_prompt = ""
|
| 267 |
-
|
| 268 |
-
if n_prompt is None:
|
| 269 |
-
n_prompt = ""
|
| 270 |
-
|
| 271 |
-
if prompt != "" and a_prompt != "":
|
| 272 |
-
a_prompt = prompt + ", " + a_prompt
|
| 273 |
-
else:
|
| 274 |
-
a_prompt = prompt + a_prompt
|
| 275 |
-
print("Final prompt: " + str(a_prompt))
|
| 276 |
-
|
| 277 |
-
denoise_image = np.array(Image.open(noisy_image if denoise_image is None else denoise_image))
|
| 278 |
-
|
| 279 |
-
if rotation == 90:
|
| 280 |
-
denoise_image = np.array(list(zip(*denoise_image[::-1])))
|
| 281 |
-
elif rotation == 180:
|
| 282 |
-
denoise_image = np.array(list(zip(*denoise_image[::-1])))
|
| 283 |
-
denoise_image = np.array(list(zip(*denoise_image[::-1])))
|
| 284 |
-
elif rotation == -90:
|
| 285 |
-
denoise_image = np.array(list(zip(*denoise_image))[::-1])
|
| 286 |
-
|
| 287 |
-
if 1 < downscale:
|
| 288 |
-
input_height, input_width, input_channel = denoise_image.shape
|
| 289 |
-
denoise_image = np.array(Image.fromarray(denoise_image).resize((input_width // downscale, input_height // downscale), Image.LANCZOS))
|
| 290 |
-
|
| 291 |
-
denoise_image = HWC3(denoise_image)
|
| 292 |
-
|
| 293 |
-
if torch.cuda.device_count() == 0:
|
| 294 |
-
gr.Warning('Set this space to GPU config to make it work.')
|
| 295 |
-
return [noisy_image, denoise_image], gr.update(label="Downloadable results in *." + output_format + " format", format = output_format, value = [denoise_image]), None, gr.update(visible=True)
|
| 296 |
-
|
| 297 |
-
if model_select != model.current_model:
|
| 298 |
-
print('load ' + model_select)
|
| 299 |
-
if model_select == 'v0-Q':
|
| 300 |
-
model.load_state_dict(ckpt_Q, strict=False)
|
| 301 |
-
elif model_select == 'v0-F':
|
| 302 |
-
model.load_state_dict(ckpt_F, strict=False)
|
| 303 |
-
model.current_model = model_select
|
| 304 |
-
|
| 305 |
-
model.ae_dtype = convert_dtype(ae_dtype)
|
| 306 |
-
model.model.dtype = convert_dtype(diff_dtype)
|
| 307 |
-
|
| 308 |
-
return restore_on_gpu(
|
| 309 |
-
noisy_image, denoise_image, prompt, a_prompt, n_prompt, num_samples, min_size, downscale, upscale, edm_steps, s_stage1, s_stage2, s_cfg, randomize_seed, seed, s_churn, s_noise, color_fix_type, diff_dtype, ae_dtype, gamma_correction, linear_CFG, linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select, output_format, allocation
|
| 310 |
-
)
|
| 311 |
-
|
| 312 |
-
def get_duration(
|
| 313 |
-
noisy_image,
|
| 314 |
-
input_image,
|
| 315 |
-
prompt,
|
| 316 |
-
a_prompt,
|
| 317 |
-
n_prompt,
|
| 318 |
-
num_samples,
|
| 319 |
-
min_size,
|
| 320 |
-
downscale,
|
| 321 |
-
upscale,
|
| 322 |
-
edm_steps,
|
| 323 |
-
s_stage1,
|
| 324 |
-
s_stage2,
|
| 325 |
-
s_cfg,
|
| 326 |
-
randomize_seed,
|
| 327 |
-
seed,
|
| 328 |
-
s_churn,
|
| 329 |
-
s_noise,
|
| 330 |
-
color_fix_type,
|
| 331 |
-
diff_dtype,
|
| 332 |
-
ae_dtype,
|
| 333 |
-
gamma_correction,
|
| 334 |
-
linear_CFG,
|
| 335 |
-
spt_linear_CFG,
|
| 336 |
-
linear_s_stage2,
|
| 337 |
-
spt_linear_s_stage2,
|
| 338 |
-
model_select,
|
| 339 |
-
output_format,
|
| 340 |
-
allocation
|
| 341 |
-
):
|
| 342 |
-
return allocation
|
| 343 |
-
|
| 344 |
-
@spaces.GPU(duration=get_duration)
|
| 345 |
-
def restore_on_gpu(
|
| 346 |
-
noisy_image,
|
| 347 |
-
input_image,
|
| 348 |
-
prompt,
|
| 349 |
-
a_prompt,
|
| 350 |
-
n_prompt,
|
| 351 |
-
num_samples,
|
| 352 |
-
min_size,
|
| 353 |
-
downscale,
|
| 354 |
-
upscale,
|
| 355 |
-
edm_steps,
|
| 356 |
-
s_stage1,
|
| 357 |
-
s_stage2,
|
| 358 |
-
s_cfg,
|
| 359 |
-
randomize_seed,
|
| 360 |
-
seed,
|
| 361 |
-
s_churn,
|
| 362 |
-
s_noise,
|
| 363 |
-
color_fix_type,
|
| 364 |
-
diff_dtype,
|
| 365 |
-
ae_dtype,
|
| 366 |
-
gamma_correction,
|
| 367 |
-
linear_CFG,
|
| 368 |
-
spt_linear_CFG,
|
| 369 |
-
linear_s_stage2,
|
| 370 |
-
spt_linear_s_stage2,
|
| 371 |
-
model_select,
|
| 372 |
-
output_format,
|
| 373 |
-
allocation
|
| 374 |
-
):
|
| 375 |
-
start = time.time()
|
| 376 |
-
print('restore ==>>')
|
| 377 |
-
|
| 378 |
-
torch.cuda.set_device(SUPIR_device)
|
| 379 |
-
|
| 380 |
-
with torch.no_grad():
|
| 381 |
-
input_image = upscale_image(input_image, upscale, unit_resolution=32, min_size=min_size)
|
| 382 |
-
LQ = np.array(input_image) / 255.0
|
| 383 |
-
LQ = np.power(LQ, gamma_correction)
|
| 384 |
-
LQ *= 255.0
|
| 385 |
-
LQ = LQ.round().clip(0, 255).astype(np.uint8)
|
| 386 |
-
LQ = LQ / 255 * 2 - 1
|
| 387 |
-
LQ = torch.tensor(LQ, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0).to(SUPIR_device)[:, :3, :, :]
|
| 388 |
-
captions = ['']
|
| 389 |
-
|
| 390 |
-
samples = model.batchify_sample(LQ, captions, num_steps=edm_steps, restoration_scale=s_stage1, s_churn=s_churn,
|
| 391 |
-
s_noise=s_noise, cfg_scale=s_cfg, control_scale=s_stage2, seed=seed,
|
| 392 |
-
num_samples=num_samples, p_p=a_prompt, n_p=n_prompt, color_fix_type=color_fix_type,
|
| 393 |
-
use_linear_CFG=linear_CFG, use_linear_control_scale=linear_s_stage2,
|
| 394 |
-
cfg_scale_start=spt_linear_CFG, control_scale_start=spt_linear_s_stage2)
|
| 395 |
-
|
| 396 |
-
x_samples = (einops.rearrange(samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().round().clip(
|
| 397 |
-
0, 255).astype(np.uint8)
|
| 398 |
-
results = [x_samples[i] for i in range(num_samples)]
|
| 399 |
-
torch.cuda.empty_cache()
|
| 400 |
-
|
| 401 |
-
# All the results have the same size
|
| 402 |
-
input_height, input_width, input_channel = np.array(input_image).shape
|
| 403 |
-
result_height, result_width, result_channel = np.array(results[0]).shape
|
| 404 |
-
|
| 405 |
-
print('<<== restore')
|
| 406 |
-
end = time.time()
|
| 407 |
-
secondes = int(end - start)
|
| 408 |
-
minutes = math.floor(secondes / 60)
|
| 409 |
-
secondes = secondes - (minutes * 60)
|
| 410 |
-
hours = math.floor(minutes / 60)
|
| 411 |
-
minutes = minutes - (hours * 60)
|
| 412 |
-
information = ("Start the process again if you want a different result. " if randomize_seed else "") + \
|
| 413 |
-
"If you don't get the image you wanted, add more details in the « Image description ». " + \
|
| 414 |
-
"The image" + (" has" if len(results) == 1 else "s have") + " been generated in " + \
|
| 415 |
-
((str(hours) + " h, ") if hours != 0 else "") + \
|
| 416 |
-
((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + \
|
| 417 |
-
str(secondes) + " sec. " + \
|
| 418 |
-
"The new image resolution is " + str(result_width) + \
|
| 419 |
-
" pixels large and " + str(result_height) + \
|
| 420 |
-
" pixels high, so a resolution of " + f'{result_width * result_height:,}' + " pixels."
|
| 421 |
-
print(information)
|
| 422 |
-
try:
|
| 423 |
-
print("Initial resolution: " + f'{input_width * input_height:,}')
|
| 424 |
-
print("Final resolution: " + f'{result_width * result_height:,}')
|
| 425 |
-
print("edm_steps: " + str(edm_steps))
|
| 426 |
-
print("num_samples: " + str(num_samples))
|
| 427 |
-
print("downscale: " + str(downscale))
|
| 428 |
-
print("Estimated minutes: " + f'{(((result_width * result_height**(1/1.75)) * input_width * input_height * (edm_steps**(1/2)) * (num_samples**(1/2.5)))**(1/2.5)) / 25000:,}')
|
| 429 |
-
except Exception as e:
|
| 430 |
-
print('Exception of Estimation')
|
| 431 |
-
|
| 432 |
-
# Only one image can be shown in the slider
|
| 433 |
-
return [noisy_image] + [results[0]], gr.update(label="Downloadable results in *." + output_format + " format", format = output_format, value = results), gr.update(value = information, visible = True), gr.update(visible=True), gr.update(visible=False), gr.update(interactive = False)
|
| 434 |
-
|
| 435 |
-
def load_and_reset(param_setting):
|
| 436 |
-
print('load_and_reset ==>>')
|
| 437 |
-
if torch.cuda.device_count() == 0:
|
| 438 |
-
gr.Warning('Set this space to GPU config to make it work.')
|
| 439 |
-
return None, None, None, None, None, None, None, None, None, None, None, None, None, None
|
| 440 |
-
edm_steps = default_setting.edm_steps
|
| 441 |
-
s_stage2 = 1.0
|
| 442 |
-
s_stage1 = -1.0
|
| 443 |
-
s_churn = 5
|
| 444 |
-
s_noise = 1.003
|
| 445 |
-
a_prompt = 'Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - ' \
|
| 446 |
-
'realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore ' \
|
| 447 |
-
'detailing, hyper sharpness, perfect without deformations.'
|
| 448 |
-
n_prompt = 'painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, ' \
|
| 449 |
-
'3D render, unreal engine, blurring, dirty, messy, worst quality, low quality, frames, watermark, ' \
|
| 450 |
-
'signature, jpeg artifacts, deformed, lowres, over-smooth'
|
| 451 |
-
color_fix_type = 'Wavelet'
|
| 452 |
-
spt_linear_s_stage2 = 0.0
|
| 453 |
-
linear_s_stage2 = False
|
| 454 |
-
linear_CFG = True
|
| 455 |
-
if param_setting == "Quality":
|
| 456 |
-
s_cfg = default_setting.s_cfg_Quality
|
| 457 |
-
spt_linear_CFG = default_setting.spt_linear_CFG_Quality
|
| 458 |
-
model_select = "v0-Q"
|
| 459 |
-
elif param_setting == "Fidelity":
|
| 460 |
-
s_cfg = default_setting.s_cfg_Fidelity
|
| 461 |
-
spt_linear_CFG = default_setting.spt_linear_CFG_Fidelity
|
| 462 |
-
model_select = "v0-F"
|
| 463 |
-
else:
|
| 464 |
-
raise NotImplementedError
|
| 465 |
-
gr.Info('The parameters are reset.')
|
| 466 |
-
print('<<== load_and_reset')
|
| 467 |
-
return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
|
| 468 |
-
spt_linear_CFG, linear_s_stage2, spt_linear_s_stage2, model_select
|
| 469 |
-
|
| 470 |
-
def log_information(result_gallery):
|
| 471 |
-
print('log_information')
|
| 472 |
-
if result_gallery is not None:
|
| 473 |
-
for i, result in enumerate(result_gallery):
|
| 474 |
-
print(result[0])
|
| 475 |
-
|
| 476 |
-
def on_select_result(result_slider, result_gallery, evt: gr.SelectData):
|
| 477 |
-
print('on_select_result')
|
| 478 |
-
if result_gallery is not None:
|
| 479 |
-
for i, result in enumerate(result_gallery):
|
| 480 |
-
print(result[0])
|
| 481 |
-
return [result_slider[0], result_gallery[evt.index][0]]
|
| 482 |
-
|
| 483 |
-
def on_render_image_example(result_example):
|
| 484 |
-
print('on_render_image_example')
|
| 485 |
-
return gr.update(value = result_example, visible = True)
|
| 486 |
-
|
| 487 |
-
title_html = """
|
| 488 |
-
<h1><center>SUPIR</center></h1>
|
| 489 |
-
<big><center>Upscale your images up to x10 freely, without account, without watermark and download it</center></big>
|
| 490 |
-
<center><big><big>🤸<big><big><big><big><big><big>🤸</big></big></big></big></big></big></big></big></center>
|
| 491 |
-
|
| 492 |
-
<p>This is an online demo of SUPIR, a practicing model scaling for photo-realistic image restoration.
|
| 493 |
-
The content added by SUPIR is <b><u>imagination, not real-world information</u></b>.
|
| 494 |
-
SUPIR is for beauty and illustration only.
|
| 495 |
-
Most of the processes last few minutes.
|
| 496 |
-
If you want to upscale AI-generated images, be noticed that <i>PixArt Sigma</i> space can directly generate 5984x5984 images.
|
| 497 |
-
Due to Gradio issues, the generated image is slightly less satured than the original.
|
| 498 |
-
Please leave a <a href="https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR/discussions/new">message in discussion</a> if you encounter issues.
|
| 499 |
-
You can also use <a href="https://huggingface.co/spaces/gokaygokay/AuraSR">AuraSR</a> to upscale x4.
|
| 500 |
-
|
| 501 |
-
<p><center><a href="https://arxiv.org/abs/2401.13627">Paper</a>   <a href="http://supir.xpixel.group/">Project Page</a>   <a href="https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai">Local Install Guide</a></center></p>
|
| 502 |
-
<p><center><a style="display:inline-block" href='https://github.com/Fanghua-Yu/SUPIR'><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/Fanghua-Yu/SUPIR?style=social"></a></center></p>
|
| 503 |
-
"""
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
claim_md = """
|
| 507 |
-
## **Piracy**
|
| 508 |
-
The images are not stored but the logs are saved during a month.
|
| 509 |
-
## **How to get SUPIR**
|
| 510 |
-
You can get SUPIR on HuggingFace by [duplicating this space](https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR?duplicate=true) and set GPU.
|
| 511 |
-
You can also install SUPIR on your computer following [this tutorial](https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai).
|
| 512 |
-
You can install _Pinokio_ on your computer and then install _SUPIR_ into it. It should be quite easy if you have an Nvidia GPU.
|
| 513 |
-
## **Terms of use**
|
| 514 |
-
By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research. Please submit a feedback to us if you get any inappropriate answer! We will collect those to keep improving our models. For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
|
| 515 |
-
## **License**
|
| 516 |
-
The service is a research preview intended for non-commercial use only, subject to the model [License](https://github.com/Fanghua-Yu/SUPIR) of SUPIR.
|
| 517 |
-
"""
|
| 518 |
-
|
| 519 |
-
js = """
|
| 520 |
-
function createGradioAnimation() {
|
| 521 |
-
window.addEventListener("beforeunload", function(e) {
|
| 522 |
-
if (document.getElementById('dummy_button_id') && !document.getElementById('dummy_button_id').disabled) {
|
| 523 |
-
var confirmationMessage = 'A process is still running. '
|
| 524 |
-
+ 'If you leave before saving, your changes will be lost.';
|
| 525 |
-
|
| 526 |
-
(e || window.event).returnValue = confirmationMessage;
|
| 527 |
-
}
|
| 528 |
-
return confirmationMessage;
|
| 529 |
-
});
|
| 530 |
-
return 'Animation created';
|
| 531 |
-
}
|
| 532 |
-
"""
|
| 533 |
-
|
| 534 |
-
# Gradio interface
|
| 535 |
-
with gr.Blocks(js=js) as interface:
|
| 536 |
-
if torch.cuda.device_count() == 0:
|
| 537 |
-
with gr.Row():
|
| 538 |
-
gr.HTML("""
|
| 539 |
-
<p style="background-color: red;"><big><big><big><b>⚠️To use SUPIR, <a href="https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR?duplicate=true">duplicate this space</a> and set a GPU with 30 GB VRAM.</b>
|
| 540 |
-
|
| 541 |
-
You can't use SUPIR directly here because this space runs on a CPU, which is not enough for SUPIR. Please provide <a href="https://huggingface.co/spaces/Fabrice-TIERCELIN/SUPIR/discussions/new">feedback</a> if you have issues.
|
| 542 |
-
</big></big></big></p>
|
| 543 |
-
""")
|
| 544 |
-
gr.HTML(title_html)
|
| 545 |
-
|
| 546 |
-
input_image = gr.Image(label="Input (*.png, *.webp, *.jpeg, *.jpg, *.gif, *.bmp, *.avif)", show_label=True, type="filepath", height=600, elem_id="image-input")
|
| 547 |
-
rotation = gr.Radio([["No rotation", 0], ["⤵ Rotate +90°", 90], ["↩ Return 180°", 180], ["⤴ Rotate -90°", -90]], label="Orientation correction", info="Will apply the following rotation before restoring the image; the AI needs a good orientation to understand the content", value=0, visible=False)
|
| 548 |
-
with gr.Group():
|
| 549 |
-
prompt = gr.Textbox(label="Image description", info="Help the AI understand what the image represents; describe as much as possible, especially the details we can't see on the original image; you can write in any language", value="", placeholder="A 33 years old man, walking, in the street, Santiago, morning, Summer, photorealistic", lines=3)
|
| 550 |
-
prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/badayvedat/LLaVA'"'>LlaVa space</a> to auto-generate the description of your image.")
|
| 551 |
-
upscale = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8], ["x9", 9], ["x10", 10]], label="Upscale factor", info="Resolution x1 to x10", value=2)
|
| 552 |
-
output_format = gr.Radio([["As input", "input"], ["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="input")
|
| 553 |
-
allocation = gr.Slider(label="GPU allocation time (in seconds)", info='lower=May abort run, higher=Quota penalty for next runs; only useful for ZeroGPU; for instance set to 88 when you have the message "You have exceeded your GPU quota (180s requested vs. 89s left)."', value=180, minimum=60, maximum=320, step=1)
|
| 554 |
-
|
| 555 |
-
with gr.Accordion("Pre-denoising (optional)", open=False):
|
| 556 |
-
gamma_correction = gr.Slider(label="Gamma Correction", info = "lower=lighter, higher=darker", minimum=0.1, maximum=2.0, value=1.0, step=0.1)
|
| 557 |
-
denoise_button = gr.Button(value="Pre-denoise")
|
| 558 |
-
denoise_image = gr.Image(label="Denoised image", show_label=True, type="filepath", sources=[], interactive = False, height=600, elem_id="image-s1")
|
| 559 |
-
denoise_information = gr.HTML(value="If present, the denoised image will be used for the restoration instead of the input image.", visible=False)
|
| 560 |
-
|
| 561 |
-
with gr.Accordion("Advanced options", open=False):
|
| 562 |
-
a_prompt = gr.Textbox(label="Additional image description",
|
| 563 |
-
info="Completes the main image description",
|
| 564 |
-
value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
|
| 565 |
-
'camera, hyper detailed photo - realistic maximum detail, 32k, Color '
|
| 566 |
-
'Grading, ultra HD, extreme meticulous detailing, skin pore detailing, clothing fabric detailing, '
|
| 567 |
-
'hyper sharpness, perfect without deformations.',
|
| 568 |
-
lines=3)
|
| 569 |
-
n_prompt = gr.Textbox(label="Negative image description",
|
| 570 |
-
info="Disambiguate by listing what the image does NOT represent",
|
| 571 |
-
value='painting, oil painting, illustration, drawing, art, sketch, anime, '
|
| 572 |
-
'cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, '
|
| 573 |
-
'worst quality, low quality, frames, watermark, signature, jpeg artifacts, '
|
| 574 |
-
'deformed, lowres, over-smooth',
|
| 575 |
-
lines=3)
|
| 576 |
-
edm_steps = gr.Slider(label="Steps", info="lower=faster, higher=more details; too many steps create a checker effect", minimum=1, maximum=200, value=default_setting.edm_steps if torch.cuda.device_count() > 0 else 1, step=1)
|
| 577 |
-
num_samples = gr.Slider(label="Num Samples", info="Number of generated results", minimum=1, maximum=4 if not args.use_image_slider else 1
|
| 578 |
-
, value=1, step=1)
|
| 579 |
-
min_size = gr.Slider(label="Minimum size", info="Minimum height, minimum width of the result", minimum=32, maximum=4096, value=1024, step=32)
|
| 580 |
-
downscale = gr.Radio([["/1", 1], ["/2", 2], ["/3", 3], ["/4", 4], ["/5", 5], ["/6", 6], ["/7", 7], ["/8", 8], ["/9", 9], ["/10", 10]], label="Pre-downscale factor", info="Reducing blurred image reduce the process time", value=1)
|
| 581 |
-
with gr.Row():
|
| 582 |
-
with gr.Column():
|
| 583 |
-
model_select = gr.Radio([["💃 Quality (v0-Q)", "v0-Q"], ["🎯 Fidelity (v0-F)", "v0-F"]], label="Model Selection", info="Pretrained model", value="v0-Q")
|
| 584 |
-
with gr.Column():
|
| 585 |
-
color_fix_type = gr.Radio([["None", "None"], ["AdaIn (improve as a photo)", "AdaIn"], ["Wavelet (for JPEG artifacts)", "Wavelet"]], label="Color-Fix Type", info="AdaIn=Improve following a style, Wavelet=For JPEG artifacts", value="AdaIn")
|
| 586 |
-
s_cfg = gr.Slider(label="Text Guidance Scale", info="lower=follow the image, higher=follow the prompt", minimum=1.0, maximum=15.0,
|
| 587 |
-
value=default_setting.s_cfg_Quality if torch.cuda.device_count() > 0 else 1.0, step=0.1)
|
| 588 |
-
s_stage2 = gr.Slider(label="Restoring Guidance Strength", minimum=0., maximum=1., value=1., step=0.05)
|
| 589 |
-
s_stage1 = gr.Slider(label="Pre-denoising Guidance Strength", minimum=-1.0, maximum=6.0, value=-1.0, step=1.0)
|
| 590 |
-
s_churn = gr.Slider(label="S-Churn", minimum=0, maximum=40, value=5, step=1)
|
| 591 |
-
s_noise = gr.Slider(label="S-Noise", minimum=1.0, maximum=1.1, value=1.003, step=0.001)
|
| 592 |
-
with gr.Row():
|
| 593 |
-
with gr.Column():
|
| 594 |
-
linear_CFG = gr.Checkbox(label="Linear CFG", value=True)
|
| 595 |
-
spt_linear_CFG = gr.Slider(label="CFG Start", minimum=1.0,
|
| 596 |
-
maximum=9.0, value=default_setting.spt_linear_CFG_Quality if torch.cuda.device_count() > 0 else 1.0, step=0.5)
|
| 597 |
-
with gr.Column():
|
| 598 |
-
linear_s_stage2 = gr.Checkbox(label="Linear Restoring Guidance", value=False)
|
| 599 |
-
spt_linear_s_stage2 = gr.Slider(label="Guidance Start", minimum=0.,
|
| 600 |
-
maximum=1., value=0., step=0.05)
|
| 601 |
-
with gr.Column():
|
| 602 |
-
diff_dtype = gr.Radio([["fp32 (precision)", "fp32"], ["fp16 (medium)", "fp16"], ["bf16 (speed)", "bf16"]], label="Diffusion Data Type", value="fp32")
|
| 603 |
-
with gr.Column():
|
| 604 |
-
ae_dtype = gr.Radio([["fp32 (precision)", "fp32"], ["bf16 (speed)", "bf16"]], label="Auto-Encoder Data Type", value="fp32")
|
| 605 |
-
randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed", value = True, info = "If checked, result is always different")
|
| 606 |
-
seed = gr.Slider(label="Seed", minimum=0, maximum=max_64_bit_int, step=1, randomize=True)
|
| 607 |
-
with gr.Group():
|
| 608 |
-
param_setting = gr.Radio(["Quality", "Fidelity"], label="Presetting", value = "Quality")
|
| 609 |
-
restart_button = gr.Button(value="Apply presetting")
|
| 610 |
-
|
| 611 |
-
with gr.Accordion("Debug", open=False):
|
| 612 |
-
input_image_debug = gr.Image(label="Image Debug", type="filepath")
|
| 613 |
-
prompt_debug = gr.Textbox(label="Prompt Debug", value='')
|
| 614 |
-
upscale_debug = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8], ["x9", 9], ["x10", 10]], label="Upscale factor", info="Resolution x1 to x10", value=2)
|
| 615 |
-
|
| 616 |
-
with gr.Column():
|
| 617 |
-
diffusion_button = gr.Button(value="🚀 Upscale/Restore", variant = "primary", elem_id = "process_button")
|
| 618 |
-
reset_btn = gr.Button(value="🧹 Reinit page", variant="stop", elem_id="reset_button", visible = False)
|
| 619 |
-
dummy_button = gr.Button(elem_id = "dummy_button_id", visible = False, interactive = False)
|
| 620 |
-
|
| 621 |
-
warning = gr.HTML(elem_id="warning", value = "<center><big>Your computer must <u>not</u> enter into standby mode.</big><br/>On Chrome, you can force to keep a tab alive in <code>chrome://discards/</code></center>", visible = False)
|
| 622 |
-
restore_information = gr.HTML(value = "Restart the process to get another result.", visible = False)
|
| 623 |
-
result_slider = ImageSlider(label = 'Comparator', show_label = False, interactive = False, elem_id = "slider1", show_download_button = False, visible = False)
|
| 624 |
-
result_gallery = gr.Gallery(label = 'Downloadable results', show_label = True, interactive = False, elem_id = "gallery1")
|
| 625 |
-
result_example = gr.HTML(elem_id="result_example", visible = False)
|
| 626 |
-
result_image_example = gr.Image(label="Example Image", visible = False)
|
| 627 |
-
|
| 628 |
-
with gr.Row(elem_id="examples", visible = False):
|
| 629 |
-
gr.Examples(
|
| 630 |
-
label = "Examples for cache",
|
| 631 |
-
examples = [
|
| 632 |
-
[
|
| 633 |
-
"./Examples/Example2.jpeg",
|
| 634 |
-
0,
|
| 635 |
-
"./Examples/Example2.jpeg",
|
| 636 |
-
"La cabeza de un gato atigrado, en una casa, fotorrealista, 8k, extremadamente detallada",
|
| 637 |
-
"Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
|
| 638 |
-
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
| 639 |
-
1, # num_samples
|
| 640 |
-
32, # min_size
|
| 641 |
-
1, # downscale
|
| 642 |
-
1, # upscale
|
| 643 |
-
100, # edm_steps
|
| 644 |
-
-1, # s_stage1
|
| 645 |
-
1, # s_stage2
|
| 646 |
-
7.5, # s_cfg
|
| 647 |
-
False, # randomize_seed
|
| 648 |
-
42, # seed
|
| 649 |
-
5, # s_churn
|
| 650 |
-
1.003, # s_noise
|
| 651 |
-
"Wavelet", # color_fix_type
|
| 652 |
-
"fp16", # diff_dtype
|
| 653 |
-
"bf16", # ae_dtype
|
| 654 |
-
1.0, # gamma_correction
|
| 655 |
-
True, # linear_CFG
|
| 656 |
-
4, # spt_linear_CFG
|
| 657 |
-
False, # linear_s_stage2
|
| 658 |
-
0., # spt_linear_s_stage2
|
| 659 |
-
"v0-Q", # model_select
|
| 660 |
-
"input", # output_format
|
| 661 |
-
60 # allocation
|
| 662 |
-
],
|
| 663 |
-
[
|
| 664 |
-
"./Examples/Example2.jpeg",
|
| 665 |
-
0,
|
| 666 |
-
"./Examples/Example2.jpeg",
|
| 667 |
-
"La cabeza de un gato atigrado, en una casa, fotorrealista, 8k, extremadamente detallada",
|
| 668 |
-
"Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
|
| 669 |
-
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
| 670 |
-
4, # num_samples
|
| 671 |
-
32, # min_size
|
| 672 |
-
1, # downscale
|
| 673 |
-
1, # upscale
|
| 674 |
-
100, # edm_steps
|
| 675 |
-
-1, # s_stage1
|
| 676 |
-
1, # s_stage2
|
| 677 |
-
7.5, # s_cfg
|
| 678 |
-
False, # randomize_seed
|
| 679 |
-
42, # seed
|
| 680 |
-
5, # s_churn
|
| 681 |
-
1.003, # s_noise
|
| 682 |
-
"Wavelet", # color_fix_type
|
| 683 |
-
"fp16", # diff_dtype
|
| 684 |
-
"bf16", # ae_dtype
|
| 685 |
-
1.0, # gamma_correction
|
| 686 |
-
True, # linear_CFG
|
| 687 |
-
4, # spt_linear_CFG
|
| 688 |
-
False, # linear_s_stage2
|
| 689 |
-
0., # spt_linear_s_stage2
|
| 690 |
-
"v0-Q", # model_select
|
| 691 |
-
"input", # output_format
|
| 692 |
-
60 # allocation
|
| 693 |
-
]
|
| 694 |
-
],
|
| 695 |
-
run_on_click = True,
|
| 696 |
-
fn = stage2_process_example,
|
| 697 |
-
inputs = [
|
| 698 |
-
input_image,
|
| 699 |
-
rotation,
|
| 700 |
-
denoise_image,
|
| 701 |
-
prompt,
|
| 702 |
-
a_prompt,
|
| 703 |
-
n_prompt,
|
| 704 |
-
num_samples,
|
| 705 |
-
min_size,
|
| 706 |
-
downscale,
|
| 707 |
-
upscale,
|
| 708 |
-
edm_steps,
|
| 709 |
-
s_stage1,
|
| 710 |
-
s_stage2,
|
| 711 |
-
s_cfg,
|
| 712 |
-
randomize_seed,
|
| 713 |
-
seed,
|
| 714 |
-
s_churn,
|
| 715 |
-
s_noise,
|
| 716 |
-
color_fix_type,
|
| 717 |
-
diff_dtype,
|
| 718 |
-
ae_dtype,
|
| 719 |
-
gamma_correction,
|
| 720 |
-
linear_CFG,
|
| 721 |
-
spt_linear_CFG,
|
| 722 |
-
linear_s_stage2,
|
| 723 |
-
spt_linear_s_stage2,
|
| 724 |
-
model_select,
|
| 725 |
-
output_format,
|
| 726 |
-
allocation
|
| 727 |
-
],
|
| 728 |
-
outputs = [
|
| 729 |
-
result_example,
|
| 730 |
-
warning,
|
| 731 |
-
dummy_button,
|
| 732 |
-
prompt_hint
|
| 733 |
-
],
|
| 734 |
-
cache_examples = True,
|
| 735 |
-
)
|
| 736 |
-
|
| 737 |
-
gr.Examples(
|
| 738 |
-
label = "Examples for demo",
|
| 739 |
-
examples = [
|
| 740 |
-
[
|
| 741 |
-
"./Examples/Example1.png",
|
| 742 |
-
0,
|
| 743 |
-
"./Examples/Example1.png",
|
| 744 |
-
"Group of people, walking, happy, in the street, photorealistic, 8k, extremely detailled",
|
| 745 |
-
"Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
|
| 746 |
-
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
| 747 |
-
2, # num_samples
|
| 748 |
-
1024, # min_size
|
| 749 |
-
1, # downscale
|
| 750 |
-
8, # upscale
|
| 751 |
-
100, # edm_steps
|
| 752 |
-
-1, # s_stage1
|
| 753 |
-
1, # s_stage2
|
| 754 |
-
7.5, # s_cfg
|
| 755 |
-
False, # randomize_seed
|
| 756 |
-
42, # seed
|
| 757 |
-
5, # s_churn
|
| 758 |
-
1.003, # s_noise
|
| 759 |
-
"AdaIn", # color_fix_type
|
| 760 |
-
"fp16", # diff_dtype
|
| 761 |
-
"bf16", # ae_dtype
|
| 762 |
-
1.0, # gamma_correction
|
| 763 |
-
True, # linear_CFG
|
| 764 |
-
4, # spt_linear_CFG
|
| 765 |
-
False, # linear_s_stage2
|
| 766 |
-
0., # spt_linear_s_stage2
|
| 767 |
-
"v0-Q", # model_select
|
| 768 |
-
"input", # output_format
|
| 769 |
-
180 # allocation
|
| 770 |
-
],
|
| 771 |
-
[
|
| 772 |
-
"./Examples/Example2.jpeg",
|
| 773 |
-
0,
|
| 774 |
-
"./Examples/Example2.jpeg",
|
| 775 |
-
"La cabeza de un gato atigrado, en una casa, fotorrealista, 8k, extremadamente detallada",
|
| 776 |
-
"Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
|
| 777 |
-
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
| 778 |
-
1, # num_samples
|
| 779 |
-
1024, # min_size
|
| 780 |
-
1, # downscale
|
| 781 |
-
1, # upscale
|
| 782 |
-
100, # edm_steps
|
| 783 |
-
-1, # s_stage1
|
| 784 |
-
1, # s_stage2
|
| 785 |
-
7.5, # s_cfg
|
| 786 |
-
False, # randomize_seed
|
| 787 |
-
42, # seed
|
| 788 |
-
5, # s_churn
|
| 789 |
-
1.003, # s_noise
|
| 790 |
-
"Wavelet", # color_fix_type
|
| 791 |
-
"fp16", # diff_dtype
|
| 792 |
-
"bf16", # ae_dtype
|
| 793 |
-
1.0, # gamma_correction
|
| 794 |
-
True, # linear_CFG
|
| 795 |
-
4, # spt_linear_CFG
|
| 796 |
-
False, # linear_s_stage2
|
| 797 |
-
0., # spt_linear_s_stage2
|
| 798 |
-
"v0-Q", # model_select
|
| 799 |
-
"input", # output_format
|
| 800 |
-
60 # allocation
|
| 801 |
-
],
|
| 802 |
-
[
|
| 803 |
-
"./Examples/Example3.webp",
|
| 804 |
-
0,
|
| 805 |
-
"./Examples/Example3.webp",
|
| 806 |
-
"A red apple",
|
| 807 |
-
"Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
|
| 808 |
-
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
| 809 |
-
1, # num_samples
|
| 810 |
-
1024, # min_size
|
| 811 |
-
1, # downscale
|
| 812 |
-
1, # upscale
|
| 813 |
-
200, # edm_steps
|
| 814 |
-
-1, # s_stage1
|
| 815 |
-
1, # s_stage2
|
| 816 |
-
7.5, # s_cfg
|
| 817 |
-
False, # randomize_seed
|
| 818 |
-
42, # seed
|
| 819 |
-
5, # s_churn
|
| 820 |
-
1.003, # s_noise
|
| 821 |
-
"Wavelet", # color_fix_type
|
| 822 |
-
"fp16", # diff_dtype
|
| 823 |
-
"bf16", # ae_dtype
|
| 824 |
-
1.0, # gamma_correction
|
| 825 |
-
True, # linear_CFG
|
| 826 |
-
4, # spt_linear_CFG
|
| 827 |
-
False, # linear_s_stage2
|
| 828 |
-
0., # spt_linear_s_stage2
|
| 829 |
-
"v0-Q", # model_select
|
| 830 |
-
"input", # output_format
|
| 831 |
-
180 # allocation
|
| 832 |
-
],
|
| 833 |
-
[
|
| 834 |
-
"./Examples/Example3.webp",
|
| 835 |
-
0,
|
| 836 |
-
"./Examples/Example3.webp",
|
| 837 |
-
"A red marble",
|
| 838 |
-
"Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
|
| 839 |
-
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, aliasing, pixel, unsharp, weird textures, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
| 840 |
-
1, # num_samples
|
| 841 |
-
1024, # min_size
|
| 842 |
-
1, # downscale
|
| 843 |
-
1, # upscale
|
| 844 |
-
200, # edm_steps
|
| 845 |
-
-1, # s_stage1
|
| 846 |
-
1, # s_stage2
|
| 847 |
-
7.5, # s_cfg
|
| 848 |
-
False, # randomize_seed
|
| 849 |
-
42, # seed
|
| 850 |
-
5, # s_churn
|
| 851 |
-
1.003, # s_noise
|
| 852 |
-
"Wavelet", # color_fix_type
|
| 853 |
-
"fp16", # diff_dtype
|
| 854 |
-
"bf16", # ae_dtype
|
| 855 |
-
1.0, # gamma_correction
|
| 856 |
-
True, # linear_CFG
|
| 857 |
-
4, # spt_linear_CFG
|
| 858 |
-
False, # linear_s_stage2
|
| 859 |
-
0., # spt_linear_s_stage2
|
| 860 |
-
"v0-Q", # model_select
|
| 861 |
-
"input", # output_format
|
| 862 |
-
180 # allocation
|
| 863 |
-
],
|
| 864 |
-
],
|
| 865 |
-
run_on_click = True,
|
| 866 |
-
fn = stage2_process,
|
| 867 |
-
inputs = [
|
| 868 |
-
input_image,
|
| 869 |
-
rotation,
|
| 870 |
-
denoise_image,
|
| 871 |
-
prompt,
|
| 872 |
-
a_prompt,
|
| 873 |
-
n_prompt,
|
| 874 |
-
num_samples,
|
| 875 |
-
min_size,
|
| 876 |
-
downscale,
|
| 877 |
-
upscale,
|
| 878 |
-
edm_steps,
|
| 879 |
-
s_stage1,
|
| 880 |
-
s_stage2,
|
| 881 |
-
s_cfg,
|
| 882 |
-
randomize_seed,
|
| 883 |
-
seed,
|
| 884 |
-
s_churn,
|
| 885 |
-
s_noise,
|
| 886 |
-
color_fix_type,
|
| 887 |
-
diff_dtype,
|
| 888 |
-
ae_dtype,
|
| 889 |
-
gamma_correction,
|
| 890 |
-
linear_CFG,
|
| 891 |
-
spt_linear_CFG,
|
| 892 |
-
linear_s_stage2,
|
| 893 |
-
spt_linear_s_stage2,
|
| 894 |
-
model_select,
|
| 895 |
-
output_format,
|
| 896 |
-
allocation
|
| 897 |
-
],
|
| 898 |
-
outputs = [
|
| 899 |
-
result_slider,
|
| 900 |
-
result_gallery,
|
| 901 |
-
restore_information,
|
| 902 |
-
reset_btn,
|
| 903 |
-
warning,
|
| 904 |
-
dummy_button
|
| 905 |
-
],
|
| 906 |
-
cache_examples = False,
|
| 907 |
-
)
|
| 908 |
-
|
| 909 |
-
with gr.Row():
|
| 910 |
-
gr.Markdown(claim_md)
|
| 911 |
-
|
| 912 |
-
input_image.upload(fn = check_upload, inputs = [
|
| 913 |
-
input_image
|
| 914 |
-
], outputs = [
|
| 915 |
-
rotation
|
| 916 |
-
], queue = False, show_progress = False)
|
| 917 |
-
|
| 918 |
-
denoise_button.click(fn = check_and_update, inputs = [
|
| 919 |
-
input_image
|
| 920 |
-
], outputs = [warning, dummy_button], queue = False, show_progress = False).success(fn = stage1_process, inputs = [
|
| 921 |
-
input_image,
|
| 922 |
-
gamma_correction,
|
| 923 |
-
diff_dtype,
|
| 924 |
-
ae_dtype
|
| 925 |
-
], outputs=[
|
| 926 |
-
denoise_image,
|
| 927 |
-
denoise_information,
|
| 928 |
-
dummy_button
|
| 929 |
-
])
|
| 930 |
-
|
| 931 |
-
diffusion_button.click(fn = update_seed, inputs = [
|
| 932 |
-
randomize_seed,
|
| 933 |
-
seed
|
| 934 |
-
], outputs = [
|
| 935 |
-
seed
|
| 936 |
-
], queue = False, show_progress = False).then(fn = check_and_update, inputs = [
|
| 937 |
-
input_image
|
| 938 |
-
], outputs = [warning, dummy_button], queue = False, show_progress = False).success(fn=stage2_process, inputs = [
|
| 939 |
-
input_image,
|
| 940 |
-
rotation,
|
| 941 |
-
denoise_image,
|
| 942 |
-
prompt,
|
| 943 |
-
a_prompt,
|
| 944 |
-
n_prompt,
|
| 945 |
-
num_samples,
|
| 946 |
-
min_size,
|
| 947 |
-
downscale,
|
| 948 |
-
upscale,
|
| 949 |
-
edm_steps,
|
| 950 |
-
s_stage1,
|
| 951 |
-
s_stage2,
|
| 952 |
-
s_cfg,
|
| 953 |
-
randomize_seed,
|
| 954 |
-
seed,
|
| 955 |
-
s_churn,
|
| 956 |
-
s_noise,
|
| 957 |
-
color_fix_type,
|
| 958 |
-
diff_dtype,
|
| 959 |
-
ae_dtype,
|
| 960 |
-
gamma_correction,
|
| 961 |
-
linear_CFG,
|
| 962 |
-
spt_linear_CFG,
|
| 963 |
-
linear_s_stage2,
|
| 964 |
-
spt_linear_s_stage2,
|
| 965 |
-
model_select,
|
| 966 |
-
output_format,
|
| 967 |
-
allocation
|
| 968 |
-
], outputs = [
|
| 969 |
-
result_slider,
|
| 970 |
-
result_gallery,
|
| 971 |
-
restore_information,
|
| 972 |
-
reset_btn,
|
| 973 |
-
warning,
|
| 974 |
-
dummy_button
|
| 975 |
-
]).success(fn = log_information, inputs = [
|
| 976 |
-
result_gallery
|
| 977 |
-
], outputs = [], queue = False, show_progress = False)
|
| 978 |
-
|
| 979 |
-
result_gallery.change(on_select_result, [result_slider, result_gallery], result_slider)
|
| 980 |
-
result_gallery.select(on_select_result, [result_slider, result_gallery], result_slider)
|
| 981 |
-
result_example.change(on_render_image_example, result_example, result_image_example)
|
| 982 |
-
|
| 983 |
-
restart_button.click(fn = load_and_reset, inputs = [
|
| 984 |
-
param_setting
|
| 985 |
-
], outputs = [
|
| 986 |
-
edm_steps,
|
| 987 |
-
s_cfg,
|
| 988 |
-
s_stage2,
|
| 989 |
-
s_stage1,
|
| 990 |
-
s_churn,
|
| 991 |
-
s_noise,
|
| 992 |
-
a_prompt,
|
| 993 |
-
n_prompt,
|
| 994 |
-
color_fix_type,
|
| 995 |
-
linear_CFG,
|
| 996 |
-
spt_linear_CFG,
|
| 997 |
-
linear_s_stage2,
|
| 998 |
-
spt_linear_s_stage2,
|
| 999 |
-
model_select
|
| 1000 |
-
])
|
| 1001 |
-
|
| 1002 |
-
reset_btn.click(fn = reset, inputs = [], outputs = [
|
| 1003 |
-
input_image,
|
| 1004 |
-
rotation,
|
| 1005 |
-
denoise_image,
|
| 1006 |
-
prompt,
|
| 1007 |
-
a_prompt,
|
| 1008 |
-
n_prompt,
|
| 1009 |
-
num_samples,
|
| 1010 |
-
min_size,
|
| 1011 |
-
downscale,
|
| 1012 |
-
upscale,
|
| 1013 |
-
edm_steps,
|
| 1014 |
-
s_stage1,
|
| 1015 |
-
s_stage2,
|
| 1016 |
-
s_cfg,
|
| 1017 |
-
randomize_seed,
|
| 1018 |
-
seed,
|
| 1019 |
-
s_churn,
|
| 1020 |
-
s_noise,
|
| 1021 |
-
color_fix_type,
|
| 1022 |
-
diff_dtype,
|
| 1023 |
-
ae_dtype,
|
| 1024 |
-
gamma_correction,
|
| 1025 |
-
linear_CFG,
|
| 1026 |
-
spt_linear_CFG,
|
| 1027 |
-
linear_s_stage2,
|
| 1028 |
-
spt_linear_s_stage2,
|
| 1029 |
-
model_select,
|
| 1030 |
-
output_format,
|
| 1031 |
-
allocation
|
| 1032 |
-
], queue = False, show_progress = False)
|
| 1033 |
-
|
| 1034 |
-
def handle_field_debug_change(input_image_debug_data, prompt_debug_data, upscale_debug_data):
|
| 1035 |
-
input_image_debug_value[0] = input_image_debug_data
|
| 1036 |
-
prompt_debug_value[0] = prompt_debug_data
|
| 1037 |
-
upscale_debug_value[0] = upscale_debug_data
|
| 1038 |
-
return []
|
| 1039 |
-
|
| 1040 |
-
input_image_debug.upload(
|
| 1041 |
-
fn=handle_field_debug_change,
|
| 1042 |
-
inputs=[input_image_debug, prompt_debug, upscale_debug],
|
| 1043 |
-
outputs=[]
|
| 1044 |
-
)
|
| 1045 |
-
|
| 1046 |
-
prompt_debug.change(
|
| 1047 |
-
fn=handle_field_debug_change,
|
| 1048 |
-
inputs=[input_image_debug, prompt_debug, upscale_debug],
|
| 1049 |
-
outputs=[]
|
| 1050 |
-
)
|
| 1051 |
-
|
| 1052 |
-
upscale_debug.change(
|
| 1053 |
-
fn=handle_field_debug_change,
|
| 1054 |
-
inputs=[input_image_debug, prompt_debug, upscale_debug],
|
| 1055 |
-
outputs=[]
|
| 1056 |
-
)
|
| 1057 |
-
|
| 1058 |
-
interface.queue(10).launch(mcp_server=True, ssr_mode=False)
|
|
|
|
| 1 |
+
# PyTorch 2.8 (temporary hack)
|
| 2 |
+
import os
|
| 3 |
+
os.system('pip install --upgrade --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu126 "torch<2.9" spaces')
|
| 4 |
+
|
| 5 |
+
# Actual demo code
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import numpy as np
|
| 8 |
+
import spaces
|
| 9 |
+
import torch
|
| 10 |
+
import random
|
| 11 |
+
from PIL import Image
|
| 12 |
+
|
| 13 |
+
from diffusers import FluxKontextPipeline
|
| 14 |
+
from diffusers.utils import load_image
|
| 15 |
+
|
| 16 |
+
from optimization import optimize_pipeline_
|
| 17 |
+
|
| 18 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 19 |
+
|
| 20 |
+
pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16).to("cuda")
|
| 21 |
+
optimize_pipeline_(pipe, image=Image.new("RGB", (512, 512)), prompt='prompt')
|
| 22 |
+
|
| 23 |
+
@spaces.GPU
|
| 24 |
+
def infer(input_image, prompt, seed=42, randomize_seed=False, guidance_scale=2.5, steps=28, progress=gr.Progress(track_tqdm=True)):
|
| 25 |
+
"""
|
| 26 |
+
Perform image editing using the FLUX.1 Kontext pipeline.
|
| 27 |
+
|
| 28 |
+
This function takes an input image and a text prompt to generate a modified version
|
| 29 |
+
of the image based on the provided instructions. It uses the FLUX.1 Kontext model
|
| 30 |
+
for contextual image editing tasks.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
input_image (PIL.Image.Image): The input image to be edited. Will be converted
|
| 34 |
+
to RGB format if not already in that format.
|
| 35 |
+
prompt (str): Text description of the desired edit to apply to the image.
|
| 36 |
+
Examples: "Remove glasses", "Add a hat", "Change background to beach".
|
| 37 |
+
seed (int, optional): Random seed for reproducible generation. Defaults to 42.
|
| 38 |
+
Must be between 0 and MAX_SEED (2^31 - 1).
|
| 39 |
+
randomize_seed (bool, optional): If True, generates a random seed instead of
|
| 40 |
+
using the provided seed value. Defaults to False.
|
| 41 |
+
guidance_scale (float, optional): Controls how closely the model follows the
|
| 42 |
+
prompt. Higher values mean stronger adherence to the prompt but may reduce
|
| 43 |
+
image quality. Range: 1.0-10.0. Defaults to 2.5.
|
| 44 |
+
steps (int, optional): Controls how many steps to run the diffusion model for.
|
| 45 |
+
Range: 1-30. Defaults to 28.
|
| 46 |
+
progress (gr.Progress, optional): Gradio progress tracker for monitoring
|
| 47 |
+
generation progress. Defaults to gr.Progress(track_tqdm=True).
|
| 48 |
+
|
| 49 |
+
Returns:
|
| 50 |
+
tuple: A 3-tuple containing:
|
| 51 |
+
- PIL.Image.Image: The generated/edited image
|
| 52 |
+
- int: The seed value used for generation (useful when randomize_seed=True)
|
| 53 |
+
- gr.update: Gradio update object to make the reuse button visible
|
| 54 |
+
|
| 55 |
+
Example:
|
| 56 |
+
>>> edited_image, used_seed, button_update = infer(
|
| 57 |
+
... input_image=my_image,
|
| 58 |
+
... prompt="Add sunglasses",
|
| 59 |
+
... seed=123,
|
| 60 |
+
... randomize_seed=False,
|
| 61 |
+
... guidance_scale=2.5
|
| 62 |
+
... )
|
| 63 |
+
"""
|
| 64 |
+
if randomize_seed:
|
| 65 |
+
seed = random.randint(0, MAX_SEED)
|
| 66 |
+
|
| 67 |
+
if input_image:
|
| 68 |
+
input_image = input_image.convert("RGB")
|
| 69 |
+
image = pipe(
|
| 70 |
+
image=input_image,
|
| 71 |
+
prompt=prompt,
|
| 72 |
+
guidance_scale=guidance_scale,
|
| 73 |
+
width = input_image.size[0],
|
| 74 |
+
height = input_image.size[1],
|
| 75 |
+
num_inference_steps=steps,
|
| 76 |
+
generator=torch.Generator().manual_seed(seed),
|
| 77 |
+
).images[0]
|
| 78 |
+
else:
|
| 79 |
+
image = pipe(
|
| 80 |
+
prompt=prompt,
|
| 81 |
+
guidance_scale=guidance_scale,
|
| 82 |
+
num_inference_steps=steps,
|
| 83 |
+
generator=torch.Generator().manual_seed(seed),
|
| 84 |
+
).images[0]
|
| 85 |
+
return image, seed, gr.Button(visible=True)
|
| 86 |
+
|
| 87 |
+
@spaces.GPU
|
| 88 |
+
def infer_example(input_image, prompt):
|
| 89 |
+
image, seed, _ = infer(input_image, prompt)
|
| 90 |
+
return image, seed
|
| 91 |
+
|
| 92 |
+
css="""
|
| 93 |
+
#col-container {
|
| 94 |
+
margin: 0 auto;
|
| 95 |
+
max-width: 960px;
|
| 96 |
+
}
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
with gr.Blocks(css=css) as demo:
|
| 100 |
+
|
| 101 |
+
with gr.Column(elem_id="col-container"):
|
| 102 |
+
gr.Markdown(f"""# FLUX.1 Kontext [dev]
|
| 103 |
+
Image editing and manipulation model guidance-distilled from FLUX.1 Kontext [pro], [[blog]](https://bfl.ai/announcements/flux-1-kontext-dev) [[model]](https://huggingface.co/black-forest-labs/FLUX.1-Kontext-dev)
|
| 104 |
+
""")
|
| 105 |
+
with gr.Row():
|
| 106 |
+
with gr.Column():
|
| 107 |
+
input_image = gr.Image(label="Upload the image for editing", type="pil")
|
| 108 |
+
with gr.Row():
|
| 109 |
+
prompt = gr.Text(
|
| 110 |
+
label="Prompt",
|
| 111 |
+
show_label=False,
|
| 112 |
+
max_lines=1,
|
| 113 |
+
placeholder="Enter your prompt for editing (e.g., 'Remove glasses', 'Add a hat')",
|
| 114 |
+
container=False,
|
| 115 |
+
)
|
| 116 |
+
run_button = gr.Button("Run", scale=0)
|
| 117 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 118 |
+
|
| 119 |
+
seed = gr.Slider(
|
| 120 |
+
label="Seed",
|
| 121 |
+
minimum=0,
|
| 122 |
+
maximum=MAX_SEED,
|
| 123 |
+
step=1,
|
| 124 |
+
value=0,
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 128 |
+
|
| 129 |
+
guidance_scale = gr.Slider(
|
| 130 |
+
label="Guidance Scale",
|
| 131 |
+
minimum=1,
|
| 132 |
+
maximum=10,
|
| 133 |
+
step=0.1,
|
| 134 |
+
value=2.5,
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
steps = gr.Slider(
|
| 138 |
+
label="Steps",
|
| 139 |
+
minimum=1,
|
| 140 |
+
maximum=30,
|
| 141 |
+
value=28,
|
| 142 |
+
step=1
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
with gr.Column():
|
| 146 |
+
result = gr.Image(label="Result", show_label=False, interactive=False)
|
| 147 |
+
reuse_button = gr.Button("Reuse this image", visible=False)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
examples = gr.Examples(
|
| 151 |
+
examples=[
|
| 152 |
+
["flowers.png", "turn the flowers into sunflowers"],
|
| 153 |
+
["monster.png", "make this monster ride a skateboard on the beach"],
|
| 154 |
+
["cat.png", "make this cat happy"]
|
| 155 |
+
],
|
| 156 |
+
inputs=[input_image, prompt],
|
| 157 |
+
outputs=[result, seed],
|
| 158 |
+
fn=infer_example,
|
| 159 |
+
cache_examples="lazy"
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
gr.on(
|
| 163 |
+
triggers=[run_button.click, prompt.submit],
|
| 164 |
+
fn = infer,
|
| 165 |
+
inputs = [input_image, prompt, seed, randomize_seed, guidance_scale, steps],
|
| 166 |
+
outputs = [result, seed, reuse_button]
|
| 167 |
+
)
|
| 168 |
+
reuse_button.click(
|
| 169 |
+
fn = lambda image: image,
|
| 170 |
+
inputs = [result],
|
| 171 |
+
outputs = [input_image]
|
| 172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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cat.png
ADDED
|
Git LFS Details
|
flowers.png
ADDED
|
Git LFS Details
|
monster.png
ADDED
|
Git LFS Details
|
optimization.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
from typing import Any
|
| 5 |
+
from typing import Callable
|
| 6 |
+
from typing import ParamSpec
|
| 7 |
+
|
| 8 |
+
import spaces
|
| 9 |
+
import torch
|
| 10 |
+
from torch.utils._pytree import tree_map_only
|
| 11 |
+
|
| 12 |
+
from optimization_utils import capture_component_call
|
| 13 |
+
from optimization_utils import aoti_compile
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
P = ParamSpec('P')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
TRANSFORMER_HIDDEN_DIM = torch.export.Dim('hidden', min=4096, max=8212)
|
| 20 |
+
|
| 21 |
+
TRANSFORMER_DYNAMIC_SHAPES = {
|
| 22 |
+
'hidden_states': {1: TRANSFORMER_HIDDEN_DIM},
|
| 23 |
+
'img_ids': {0: TRANSFORMER_HIDDEN_DIM},
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
INDUCTOR_CONFIGS = {
|
| 27 |
+
'conv_1x1_as_mm': True,
|
| 28 |
+
'epilogue_fusion': False,
|
| 29 |
+
'coordinate_descent_tuning': True,
|
| 30 |
+
'coordinate_descent_check_all_directions': True,
|
| 31 |
+
'max_autotune': True,
|
| 32 |
+
'triton.cudagraphs': True,
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kwargs):
|
| 37 |
+
|
| 38 |
+
@spaces.GPU(duration=1500)
|
| 39 |
+
def compile_transformer():
|
| 40 |
+
|
| 41 |
+
with capture_component_call(pipeline, 'transformer') as call:
|
| 42 |
+
pipeline(*args, **kwargs)
|
| 43 |
+
|
| 44 |
+
dynamic_shapes = tree_map_only((torch.Tensor, bool), lambda t: None, call.kwargs)
|
| 45 |
+
dynamic_shapes |= TRANSFORMER_DYNAMIC_SHAPES
|
| 46 |
+
|
| 47 |
+
pipeline.transformer.fuse_qkv_projections()
|
| 48 |
+
|
| 49 |
+
exported = torch.export.export(
|
| 50 |
+
mod=pipeline.transformer,
|
| 51 |
+
args=call.args,
|
| 52 |
+
kwargs=call.kwargs,
|
| 53 |
+
dynamic_shapes=dynamic_shapes,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
return aoti_compile(exported, INDUCTOR_CONFIGS)
|
| 57 |
+
|
| 58 |
+
transformer_config = pipeline.transformer.config
|
| 59 |
+
pipeline.transformer = compile_transformer()
|
| 60 |
+
pipeline.transformer.config = transformer_config # pyright: ignore[reportAttributeAccessIssue]
|
optimization_utils.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
"""
|
| 3 |
+
import contextlib
|
| 4 |
+
from contextvars import ContextVar
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
from typing import Any
|
| 7 |
+
from typing import cast
|
| 8 |
+
from unittest.mock import patch
|
| 9 |
+
|
| 10 |
+
import torch
|
| 11 |
+
from torch._inductor.package.package import package_aoti
|
| 12 |
+
from torch.export.pt2_archive._package import AOTICompiledModel
|
| 13 |
+
from torch.export.pt2_archive._package_weights import TensorProperties
|
| 14 |
+
from torch.export.pt2_archive._package_weights import Weights
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
INDUCTOR_CONFIGS_OVERRIDES = {
|
| 18 |
+
'aot_inductor.package_constants_in_so': False,
|
| 19 |
+
'aot_inductor.package_constants_on_disk': True,
|
| 20 |
+
'aot_inductor.package': True,
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ZeroGPUCompiledModel:
|
| 25 |
+
def __init__(self, archive_file: torch.types.FileLike, weights: Weights, cuda: bool = False):
|
| 26 |
+
self.archive_file = archive_file
|
| 27 |
+
self.weights = weights
|
| 28 |
+
if cuda:
|
| 29 |
+
self.weights_to_cuda_()
|
| 30 |
+
self.compiled_model: ContextVar[AOTICompiledModel | None] = ContextVar('compiled_model', default=None)
|
| 31 |
+
def weights_to_cuda_(self):
|
| 32 |
+
for name in self.weights:
|
| 33 |
+
tensor, properties = self.weights.get_weight(name)
|
| 34 |
+
self.weights[name] = (tensor.to('cuda'), properties)
|
| 35 |
+
def __call__(self, *args, **kwargs):
|
| 36 |
+
if (compiled_model := self.compiled_model.get()) is None:
|
| 37 |
+
constants_map = {name: value[0] for name, value in self.weights.items()}
|
| 38 |
+
compiled_model = cast(AOTICompiledModel, torch._inductor.aoti_load_package(self.archive_file))
|
| 39 |
+
compiled_model.load_constants(constants_map, check_full_update=True, user_managed=True)
|
| 40 |
+
self.compiled_model.set(compiled_model)
|
| 41 |
+
return compiled_model(*args, **kwargs)
|
| 42 |
+
def __reduce__(self):
|
| 43 |
+
weight_dict: dict[str, tuple[torch.Tensor, TensorProperties]] = {}
|
| 44 |
+
for name in self.weights:
|
| 45 |
+
tensor, properties = self.weights.get_weight(name)
|
| 46 |
+
tensor_ = torch.empty_like(tensor, device='cpu').pin_memory()
|
| 47 |
+
weight_dict[name] = (tensor_.copy_(tensor).detach().share_memory_(), properties)
|
| 48 |
+
return ZeroGPUCompiledModel, (self.archive_file, Weights(weight_dict), True)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def aoti_compile(
|
| 52 |
+
exported_program: torch.export.ExportedProgram,
|
| 53 |
+
inductor_configs: dict[str, Any] | None = None,
|
| 54 |
+
):
|
| 55 |
+
inductor_configs = (inductor_configs or {}) | INDUCTOR_CONFIGS_OVERRIDES
|
| 56 |
+
gm = cast(torch.fx.GraphModule, exported_program.module())
|
| 57 |
+
assert exported_program.example_inputs is not None
|
| 58 |
+
args, kwargs = exported_program.example_inputs
|
| 59 |
+
artifacts = torch._inductor.aot_compile(gm, args, kwargs, options=inductor_configs)
|
| 60 |
+
archive_file = BytesIO()
|
| 61 |
+
files: list[str | Weights] = [file for file in artifacts if isinstance(file, str)]
|
| 62 |
+
package_aoti(archive_file, files)
|
| 63 |
+
weights, = (artifact for artifact in artifacts if isinstance(artifact, Weights))
|
| 64 |
+
return ZeroGPUCompiledModel(archive_file, weights)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@contextlib.contextmanager
|
| 68 |
+
def capture_component_call(
|
| 69 |
+
pipeline: Any,
|
| 70 |
+
component_name: str,
|
| 71 |
+
component_method='forward',
|
| 72 |
+
):
|
| 73 |
+
|
| 74 |
+
class CapturedCallException(Exception):
|
| 75 |
+
def __init__(self, *args, **kwargs):
|
| 76 |
+
super().__init__()
|
| 77 |
+
self.args = args
|
| 78 |
+
self.kwargs = kwargs
|
| 79 |
+
|
| 80 |
+
class CapturedCall:
|
| 81 |
+
def __init__(self):
|
| 82 |
+
self.args: tuple[Any, ...] = ()
|
| 83 |
+
self.kwargs: dict[str, Any] = {}
|
| 84 |
+
|
| 85 |
+
component = getattr(pipeline, component_name)
|
| 86 |
+
captured_call = CapturedCall()
|
| 87 |
+
|
| 88 |
+
def capture_call(*args, **kwargs):
|
| 89 |
+
raise CapturedCallException(*args, **kwargs)
|
| 90 |
+
|
| 91 |
+
with patch.object(component, component_method, new=capture_call):
|
| 92 |
+
try:
|
| 93 |
+
yield captured_call
|
| 94 |
+
except CapturedCallException as e:
|
| 95 |
+
captured_call.args = e.args
|
| 96 |
+
captured_call.kwargs = e.kwargs
|
requirements.txt
CHANGED
|
@@ -1,43 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
numpy==1.26.4
|
| 7 |
-
requests==2.32.4
|
| 8 |
-
sentencepiece==0.2.0
|
| 9 |
-
tokenizers==0.19.1
|
| 10 |
-
torchvision==0.22.0
|
| 11 |
-
uvicorn==0.34.3
|
| 12 |
-
wandb==0.20.1
|
| 13 |
-
httpx==0.28.1
|
| 14 |
-
transformers==4.43.0
|
| 15 |
-
accelerate==1.8.0
|
| 16 |
-
scikit-learn==1.7.0
|
| 17 |
-
einops==0.8.1
|
| 18 |
-
einops-exts==0.0.4
|
| 19 |
-
timm==1.0.15
|
| 20 |
-
openai-clip==1.0.1
|
| 21 |
-
fsspec==2025.5.1
|
| 22 |
-
kornia==0.8.1
|
| 23 |
-
matplotlib==3.10.3
|
| 24 |
-
ninja==1.11.1.4
|
| 25 |
-
omegaconf==2.3.0
|
| 26 |
-
opencv-python==4.11.0.86
|
| 27 |
-
pandas==2.3.0
|
| 28 |
-
pillow==11.2.1
|
| 29 |
-
pytorch-lightning==2.5.1.post0
|
| 30 |
-
PyYAML==6.0.2
|
| 31 |
-
scipy==1.15.3
|
| 32 |
-
tqdm==4.67.1
|
| 33 |
-
triton==3.3.0
|
| 34 |
-
urllib3==2.4.0
|
| 35 |
-
webdataset==0.2.111
|
| 36 |
-
xformers==0.0.30
|
| 37 |
-
facexlib==0.3.0
|
| 38 |
-
k-diffusion==0.1.1.post1
|
| 39 |
-
diffusers==0.33.1
|
| 40 |
-
imageio==2.37.0
|
| 41 |
-
pillow-heif==0.22.0
|
| 42 |
-
|
| 43 |
-
open-clip-torch==2.24.0
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
git+https://github.com/huggingface/diffusers.git
|
| 3 |
+
accelerate
|
| 4 |
+
safetensors
|
| 5 |
+
sentencepiece
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|