log_information
Browse files- gradio_demo.py +71 -70
gradio_demo.py
CHANGED
|
@@ -147,124 +147,113 @@ def stage2_process(
|
|
| 147 |
output_format,
|
| 148 |
allocation
|
| 149 |
):
|
| 150 |
-
print('allocation')
|
| 151 |
-
print(allocation)
|
| 152 |
if allocation == 1:
|
| 153 |
return restore_in_1min(
|
| 154 |
-
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
|
| 155 |
)
|
| 156 |
if allocation == 2:
|
| 157 |
return restore_in_2min(
|
| 158 |
-
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
|
| 159 |
)
|
| 160 |
if allocation == 3:
|
| 161 |
return restore_in_3min(
|
| 162 |
-
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
|
| 163 |
)
|
| 164 |
if allocation == 4:
|
| 165 |
return restore_in_4min(
|
| 166 |
-
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
|
| 167 |
)
|
| 168 |
if allocation == 5:
|
| 169 |
return restore_in_5min(
|
| 170 |
-
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
|
| 171 |
)
|
| 172 |
if allocation == 7:
|
| 173 |
return restore_in_7min(
|
| 174 |
-
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
|
| 175 |
)
|
| 176 |
if allocation == 8:
|
| 177 |
return restore_in_8min(
|
| 178 |
-
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
|
| 179 |
)
|
| 180 |
if allocation == 9:
|
| 181 |
return restore_in_9min(
|
| 182 |
-
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
|
| 183 |
)
|
| 184 |
else:
|
| 185 |
return restore_in_6min(
|
| 186 |
-
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
|
| 187 |
)
|
| 188 |
|
| 189 |
@spaces.GPU(duration=60)
|
| 190 |
def restore_in_1min(
|
| 191 |
-
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
|
| 192 |
):
|
| 193 |
-
print('1 min')
|
| 194 |
return restore(
|
| 195 |
-
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
|
| 196 |
)
|
| 197 |
|
| 198 |
@spaces.GPU(duration=120)
|
| 199 |
def restore_in_2min(
|
| 200 |
-
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
|
| 201 |
):
|
| 202 |
-
print('2 min')
|
| 203 |
return restore(
|
| 204 |
-
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
|
| 205 |
)
|
| 206 |
|
| 207 |
@spaces.GPU(duration=180)
|
| 208 |
def restore_in_3min(
|
| 209 |
-
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
|
| 210 |
):
|
| 211 |
-
print('3 min')
|
| 212 |
return restore(
|
| 213 |
-
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
|
| 214 |
)
|
| 215 |
|
| 216 |
@spaces.GPU(duration=240)
|
| 217 |
def restore_in_4min(
|
| 218 |
-
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
|
| 219 |
):
|
| 220 |
-
print('4 min')
|
| 221 |
return restore(
|
| 222 |
-
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
|
| 223 |
)
|
| 224 |
|
| 225 |
@spaces.GPU(duration=300)
|
| 226 |
def restore_in_5min(
|
| 227 |
-
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
|
| 228 |
):
|
| 229 |
-
print('5 min')
|
| 230 |
return restore(
|
| 231 |
-
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
|
| 232 |
)
|
| 233 |
|
| 234 |
@spaces.GPU(duration=360)
|
| 235 |
def restore_in_6min(
|
| 236 |
-
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
|
| 237 |
):
|
| 238 |
-
print('6 min')
|
| 239 |
return restore(
|
| 240 |
-
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
|
| 241 |
)
|
| 242 |
|
| 243 |
@spaces.GPU(duration=420)
|
| 244 |
def restore_in_7min(
|
| 245 |
-
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
|
| 246 |
):
|
| 247 |
-
print('7 min')
|
| 248 |
return restore(
|
| 249 |
-
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
|
| 250 |
)
|
| 251 |
|
| 252 |
@spaces.GPU(duration=480)
|
| 253 |
def restore_in_8min(
|
| 254 |
-
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
|
| 255 |
):
|
| 256 |
-
print('8 min')
|
| 257 |
return restore(
|
| 258 |
-
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
|
| 259 |
)
|
| 260 |
|
| 261 |
@spaces.GPU(duration=540)
|
| 262 |
def restore_in_9min(
|
| 263 |
-
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
|
| 264 |
):
|
| 265 |
-
print('9 min')
|
| 266 |
return restore(
|
| 267 |
-
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
|
| 268 |
)
|
| 269 |
|
| 270 |
def restore(
|
|
@@ -294,45 +283,50 @@ def restore(
|
|
| 294 |
spt_linear_CFG,
|
| 295 |
spt_linear_s_stage2,
|
| 296 |
model_select,
|
| 297 |
-
output_format
|
|
|
|
| 298 |
):
|
| 299 |
start = time.time()
|
| 300 |
print('stage2_process ==>>')
|
| 301 |
-
print(noisy_image)
|
| 302 |
-
print(denoise_image)
|
| 303 |
-
print(prompt)
|
| 304 |
-
print(a_prompt)
|
| 305 |
-
print(n_prompt)
|
| 306 |
-
print(num_samples)
|
| 307 |
-
print(min_size)
|
| 308 |
-
print(downscale)
|
| 309 |
-
print(upscale)
|
| 310 |
-
print(edm_steps)
|
| 311 |
-
print(s_stage1)
|
| 312 |
-
print(s_stage2)
|
| 313 |
-
print(s_cfg)
|
| 314 |
-
print(randomize_seed)
|
| 315 |
-
print(seed)
|
| 316 |
-
print(s_churn)
|
| 317 |
-
print(s_noise)
|
| 318 |
-
print(color_fix_type)
|
| 319 |
-
print(diff_dtype)
|
| 320 |
-
print(ae_dtype)
|
| 321 |
-
print(gamma_correction)
|
| 322 |
-
print(linear_CFG)
|
| 323 |
-
print(linear_s_stage2)
|
| 324 |
-
print(spt_linear_CFG)
|
| 325 |
-
print(spt_linear_s_stage2)
|
| 326 |
-
print(model_select)
|
| 327 |
-
print(output_format)
|
|
|
|
|
|
|
| 328 |
if torch.cuda.device_count() == 0:
|
| 329 |
gr.Warning('Set this space to GPU config to make it work.')
|
| 330 |
return None, None, None, None
|
|
|
|
| 331 |
if output_format == "input":
|
| 332 |
if noisy_image is None:
|
| 333 |
output_format = "png"
|
| 334 |
else:
|
| 335 |
output_format = noisy_image.format
|
|
|
|
| 336 |
input_image = noisy_image if denoise_image is None else denoise_image
|
| 337 |
if 1 < downscale:
|
| 338 |
input_height, input_width, input_channel = np.array(input_image).shape
|
|
@@ -402,7 +396,7 @@ def restore(
|
|
| 402 |
hours = math.floor(minutes / 60)
|
| 403 |
minutes = minutes - (hours * 60)
|
| 404 |
information = ("Start the process again if you want a different result. " if randomize_seed else "") + \
|
| 405 |
-
"Wait
|
| 406 |
"The image(s) has(ve) been generated in " + \
|
| 407 |
((str(hours) + " h, ") if hours != 0 else "") + \
|
| 408 |
((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + \
|
|
@@ -450,10 +444,14 @@ def load_and_reset(param_setting):
|
|
| 450 |
return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
|
| 451 |
linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
def on_select_result(result_gallery, evt: gr.SelectData):
|
| 454 |
print('on_select_result')
|
| 455 |
-
print(result_gallery[0])
|
| 456 |
-
print(result_gallery[evt.index])
|
| 457 |
return [result_gallery[0][0], result_gallery[evt.index][0]]
|
| 458 |
|
| 459 |
def submit_feedback(event_id, fb_score, fb_text):
|
|
@@ -480,6 +478,7 @@ title_html = """
|
|
| 480 |
The aim of SUPIR is the beauty and the illustration.
|
| 481 |
Most of the processes only last few minutes.
|
| 482 |
This demo can handle huge images but the process will be aborted if it lasts more than 9 min.
|
|
|
|
| 483 |
|
| 484 |
<p><center><a href="https://arxiv.org/abs/2401.13627">Paper</a>   <a href="http://supir.xpixel.group/">Project Page</a>   <a href="https://github.com/Fanghua-Yu/SUPIR/blob/master/assets/DemoGuide.png">How to play</a>   <a href="https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai">Local Install Guide</a></center></p>
|
| 485 |
"""
|
|
@@ -765,7 +764,9 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 765 |
result_gallery,
|
| 766 |
restore_information,
|
| 767 |
event_id
|
| 768 |
-
])
|
|
|
|
|
|
|
| 769 |
|
| 770 |
result_gallery.select(on_select_result, result_gallery, result_slider)
|
| 771 |
|
|
|
|
| 147 |
output_format,
|
| 148 |
allocation
|
| 149 |
):
|
|
|
|
|
|
|
| 150 |
if allocation == 1:
|
| 151 |
return restore_in_1min(
|
| 152 |
+
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
|
| 153 |
)
|
| 154 |
if allocation == 2:
|
| 155 |
return restore_in_2min(
|
| 156 |
+
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
|
| 157 |
)
|
| 158 |
if allocation == 3:
|
| 159 |
return restore_in_3min(
|
| 160 |
+
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
|
| 161 |
)
|
| 162 |
if allocation == 4:
|
| 163 |
return restore_in_4min(
|
| 164 |
+
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
|
| 165 |
)
|
| 166 |
if allocation == 5:
|
| 167 |
return restore_in_5min(
|
| 168 |
+
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
|
| 169 |
)
|
| 170 |
if allocation == 7:
|
| 171 |
return restore_in_7min(
|
| 172 |
+
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
|
| 173 |
)
|
| 174 |
if allocation == 8:
|
| 175 |
return restore_in_8min(
|
| 176 |
+
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
|
| 177 |
)
|
| 178 |
if allocation == 9:
|
| 179 |
return restore_in_9min(
|
| 180 |
+
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
|
| 181 |
)
|
| 182 |
else:
|
| 183 |
return restore_in_6min(
|
| 184 |
+
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
|
| 185 |
)
|
| 186 |
|
| 187 |
@spaces.GPU(duration=60)
|
| 188 |
def restore_in_1min(
|
| 189 |
+
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
|
| 190 |
):
|
|
|
|
| 191 |
return restore(
|
| 192 |
+
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
|
| 193 |
)
|
| 194 |
|
| 195 |
@spaces.GPU(duration=120)
|
| 196 |
def restore_in_2min(
|
| 197 |
+
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
|
| 198 |
):
|
|
|
|
| 199 |
return restore(
|
| 200 |
+
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
|
| 201 |
)
|
| 202 |
|
| 203 |
@spaces.GPU(duration=180)
|
| 204 |
def restore_in_3min(
|
| 205 |
+
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
|
| 206 |
):
|
|
|
|
| 207 |
return restore(
|
| 208 |
+
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
|
| 209 |
)
|
| 210 |
|
| 211 |
@spaces.GPU(duration=240)
|
| 212 |
def restore_in_4min(
|
| 213 |
+
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
|
| 214 |
):
|
|
|
|
| 215 |
return restore(
|
| 216 |
+
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
|
| 217 |
)
|
| 218 |
|
| 219 |
@spaces.GPU(duration=300)
|
| 220 |
def restore_in_5min(
|
| 221 |
+
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
|
| 222 |
):
|
|
|
|
| 223 |
return restore(
|
| 224 |
+
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
|
| 225 |
)
|
| 226 |
|
| 227 |
@spaces.GPU(duration=360)
|
| 228 |
def restore_in_6min(
|
| 229 |
+
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
|
| 230 |
):
|
|
|
|
| 231 |
return restore(
|
| 232 |
+
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
|
| 233 |
)
|
| 234 |
|
| 235 |
@spaces.GPU(duration=420)
|
| 236 |
def restore_in_7min(
|
| 237 |
+
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
|
| 238 |
):
|
|
|
|
| 239 |
return restore(
|
| 240 |
+
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
|
| 241 |
)
|
| 242 |
|
| 243 |
@spaces.GPU(duration=480)
|
| 244 |
def restore_in_8min(
|
| 245 |
+
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
|
| 246 |
):
|
|
|
|
| 247 |
return restore(
|
| 248 |
+
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
|
| 249 |
)
|
| 250 |
|
| 251 |
@spaces.GPU(duration=540)
|
| 252 |
def restore_in_9min(
|
| 253 |
+
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
|
| 254 |
):
|
|
|
|
| 255 |
return restore(
|
| 256 |
+
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
|
| 257 |
)
|
| 258 |
|
| 259 |
def restore(
|
|
|
|
| 283 |
spt_linear_CFG,
|
| 284 |
spt_linear_s_stage2,
|
| 285 |
model_select,
|
| 286 |
+
output_format,
|
| 287 |
+
allocation
|
| 288 |
):
|
| 289 |
start = time.time()
|
| 290 |
print('stage2_process ==>>')
|
| 291 |
+
print("noisy_image: " + str(noisy_image))
|
| 292 |
+
print("denoise_image: " + str(denoise_image))
|
| 293 |
+
print("prompt: " + str(prompt))
|
| 294 |
+
print("a_prompt: " + str(a_prompt))
|
| 295 |
+
print("n_prompt: " + str(n_prompt))
|
| 296 |
+
print("num_samples: " + str(num_samples))
|
| 297 |
+
print("min_size: " + str(min_size))
|
| 298 |
+
print("downscale: " + str(downscale))
|
| 299 |
+
print("upscale: " + str(upscale))
|
| 300 |
+
print("edm_steps: " + str(edm_steps))
|
| 301 |
+
print("s_stage1: " + str(s_stage1))
|
| 302 |
+
print("s_stage2: " + str(s_stage2))
|
| 303 |
+
print("s_cfg: " + str(s_cfg))
|
| 304 |
+
print("randomize_seed: " + str(randomize_seed))
|
| 305 |
+
print("seed: " + str(seed))
|
| 306 |
+
print("s_churn: " + str(s_churn))
|
| 307 |
+
print("s_noise: " + str(s_noise))
|
| 308 |
+
print("color_fix_type: " + str(color_fix_type))
|
| 309 |
+
print("diff_dtype: " + str(diff_dtype))
|
| 310 |
+
print("ae_dtype: " + str(ae_dtype))
|
| 311 |
+
print("gamma_correction: " + str(gamma_correction))
|
| 312 |
+
print("linear_CFG: " + str(linear_CFG))
|
| 313 |
+
print("linear_s_stage2: " + str(linear_s_stage2))
|
| 314 |
+
print("spt_linear_CFG: " + str(spt_linear_CFG))
|
| 315 |
+
print("spt_linear_s_stage2: " + str(spt_linear_s_stage2))
|
| 316 |
+
print("model_select: " + str(model_select))
|
| 317 |
+
print("output_format: " + str(output_format))
|
| 318 |
+
print("GPU time allocation: " + str(allocation) + " min")
|
| 319 |
+
|
| 320 |
if torch.cuda.device_count() == 0:
|
| 321 |
gr.Warning('Set this space to GPU config to make it work.')
|
| 322 |
return None, None, None, None
|
| 323 |
+
|
| 324 |
if output_format == "input":
|
| 325 |
if noisy_image is None:
|
| 326 |
output_format = "png"
|
| 327 |
else:
|
| 328 |
output_format = noisy_image.format
|
| 329 |
+
|
| 330 |
input_image = noisy_image if denoise_image is None else denoise_image
|
| 331 |
if 1 < downscale:
|
| 332 |
input_height, input_width, input_channel = np.array(input_image).shape
|
|
|
|
| 396 |
hours = math.floor(minutes / 60)
|
| 397 |
minutes = minutes - (hours * 60)
|
| 398 |
information = ("Start the process again if you want a different result. " if randomize_seed else "") + \
|
| 399 |
+
"Wait " + str(allocation) + " min before a new run to avoid time penalty. " + \
|
| 400 |
"The image(s) has(ve) been generated in " + \
|
| 401 |
((str(hours) + " h, ") if hours != 0 else "") + \
|
| 402 |
((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + \
|
|
|
|
| 444 |
return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
|
| 445 |
linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select
|
| 446 |
|
| 447 |
+
def log_information(result_gallery):
|
| 448 |
+
print('log_information')
|
| 449 |
+
if result_gallery is not None:
|
| 450 |
+
for i, result in enumerate(result_gallery):
|
| 451 |
+
print(result[0][0])
|
| 452 |
+
|
| 453 |
def on_select_result(result_gallery, evt: gr.SelectData):
|
| 454 |
print('on_select_result')
|
|
|
|
|
|
|
| 455 |
return [result_gallery[0][0], result_gallery[evt.index][0]]
|
| 456 |
|
| 457 |
def submit_feedback(event_id, fb_score, fb_text):
|
|
|
|
| 478 |
The aim of SUPIR is the beauty and the illustration.
|
| 479 |
Most of the processes only last few minutes.
|
| 480 |
This demo can handle huge images but the process will be aborted if it lasts more than 9 min.
|
| 481 |
+
Please leave a message in discussion if you encounter issues.
|
| 482 |
|
| 483 |
<p><center><a href="https://arxiv.org/abs/2401.13627">Paper</a>   <a href="http://supir.xpixel.group/">Project Page</a>   <a href="https://github.com/Fanghua-Yu/SUPIR/blob/master/assets/DemoGuide.png">How to play</a>   <a href="https://huggingface.co/blog/MonsterMMORPG/supir-sota-image-upscale-better-than-magnific-ai">Local Install Guide</a></center></p>
|
| 484 |
"""
|
|
|
|
| 764 |
result_gallery,
|
| 765 |
restore_information,
|
| 766 |
event_id
|
| 767 |
+
]).success(fn = log_information, inputs = [
|
| 768 |
+
result_gallery
|
| 769 |
+
], outputs = [], queue = False, show_progress = False)
|
| 770 |
|
| 771 |
result_gallery.select(on_select_result, result_gallery, result_slider)
|
| 772 |
|