Better parameter order
Browse files- gradio_demo.py +57 -29
gradio_demo.py
CHANGED
|
@@ -117,13 +117,36 @@ def llave_process(input_image, temperature, top_p, qs=None):
|
|
| 117 |
return captions[0]
|
| 118 |
|
| 119 |
@spaces.GPU(duration=240)
|
| 120 |
-
def stage2_process(
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
print('Start stage2_process')
|
| 124 |
if torch.cuda.device_count() == 0:
|
| 125 |
gr.Warning('Set this space to GPU config to make it work.')
|
| 126 |
return None, None
|
|
|
|
| 127 |
torch.cuda.set_device(SUPIR_device)
|
| 128 |
event_id = str(time.time_ns())
|
| 129 |
event_dict = {'event_id': event_id, 'localtime': time.ctime(), 'prompt': prompt, 'a_prompt': a_prompt,
|
|
@@ -184,7 +207,7 @@ def load_and_reset(param_setting):
|
|
| 184 |
print('Start load_and_reset')
|
| 185 |
if torch.cuda.device_count() == 0:
|
| 186 |
gr.Warning('Set this space to GPU config to make it work.')
|
| 187 |
-
return None, None, None, None, None, None, None, None, None, None, None, None, None
|
| 188 |
edm_steps = default_setting.edm_steps
|
| 189 |
s_stage2 = 1.0
|
| 190 |
s_stage1 = -1.0
|
|
@@ -203,15 +226,17 @@ def load_and_reset(param_setting):
|
|
| 203 |
if param_setting == "Quality":
|
| 204 |
s_cfg = default_setting.s_cfg_Quality
|
| 205 |
spt_linear_CFG = default_setting.spt_linear_CFG_Quality
|
|
|
|
| 206 |
elif param_setting == "Fidelity":
|
| 207 |
s_cfg = default_setting.s_cfg_Fidelity
|
| 208 |
spt_linear_CFG = default_setting.spt_linear_CFG_Fidelity
|
|
|
|
| 209 |
else:
|
| 210 |
raise NotImplementedError
|
| 211 |
gr.Info('The parameters are reset.')
|
| 212 |
print('End load_and_reset')
|
| 213 |
return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
|
| 214 |
-
linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2
|
| 215 |
|
| 216 |
|
| 217 |
def submit_feedback(event_id, fb_score, fb_text):
|
|
@@ -229,10 +254,10 @@ def submit_feedback(event_id, fb_score, fb_text):
|
|
| 229 |
|
| 230 |
title_html = """
|
| 231 |
<h1><center>SUPIR</center></h1>
|
| 232 |
-
<center>Upscale your images up to x8 freely, without account, without watermark and download it</center>
|
| 233 |
<br/>
|
| 234 |
|
| 235 |
-
<p>SUPIR is a practicing model scaling for photo-realistic image restoration. It is still a research project under tested and is not yet a stable commercial product. LLaVa is not
|
| 236 |
|
| 237 |
<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>
|
| 238 |
"""
|
|
@@ -281,18 +306,7 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 281 |
qs = gr.Textbox(label="Question", info="Ask LLaVa what description you want", value="Describe the image and its style in a very detailed manner. The image is a realistic photography, not an art painting.", lines=3)
|
| 282 |
|
| 283 |
with gr.Accordion("Restoring options", open=False):
|
| 284 |
-
num_samples = gr.Slider(label="Num Samples", info="Number of generated results; I discourage to increase because the process is limited to 3 min", minimum=1, maximum=4 if not args.use_image_slider else 1
|
| 285 |
-
, value=1, step=1)
|
| 286 |
upscale = gr.Slider(label="Upscale factor", info="Resolution x1, x2, x3, x4, x5, x6, x7 or x8", minimum=1, maximum=8, value=2, step=1)
|
| 287 |
-
edm_steps = gr.Slider(label="Steps", info="lower=faster, higher=more details", minimum=1, maximum=200, value=default_setting.edm_steps if torch.cuda.device_count() > 0 else 1, step=1)
|
| 288 |
-
s_cfg = gr.Slider(label="Text Guidance Scale", info="lower=follow the image, higher=follow the prompt", minimum=1.0, maximum=15.0,
|
| 289 |
-
value=default_setting.s_cfg_Quality if torch.cuda.device_count() > 0 else 1.0, step=0.1)
|
| 290 |
-
s_stage2 = gr.Slider(label="Restoring Guidance Strength", minimum=0., maximum=1., value=1., step=0.05)
|
| 291 |
-
s_stage1 = gr.Slider(label="Pre-denoising Guidance Strength", minimum=-1.0, maximum=6.0, value=-1.0, step=1.0)
|
| 292 |
-
randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed", value = True, info = "If checked, result is always different")
|
| 293 |
-
seed = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, randomize=True)
|
| 294 |
-
s_churn = gr.Slider(label="S-Churn", minimum=0, maximum=40, value=5, step=1)
|
| 295 |
-
s_noise = gr.Slider(label="S-Noise", minimum=1.0, maximum=1.1, value=1.003, step=0.001)
|
| 296 |
a_prompt = gr.Textbox(label="Default Positive Prompt",
|
| 297 |
info="Describe what the image represents",
|
| 298 |
value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
|
|
@@ -307,6 +321,22 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 307 |
'worst quality, low quality, frames, watermark, signature, jpeg artifacts, '
|
| 308 |
'deformed, lowres, over-smooth',
|
| 309 |
lines=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
with gr.Row():
|
| 311 |
with gr.Column():
|
| 312 |
linear_CFG = gr.Checkbox(label="Linear CFG", value=True)
|
|
@@ -323,12 +353,8 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 323 |
with gr.Column():
|
| 324 |
ae_dtype = gr.Radio(['fp32', 'bf16'], label="Auto-Encoder Data Type", value="bf16",
|
| 325 |
interactive=True)
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
interactive=True)
|
| 329 |
-
with gr.Column():
|
| 330 |
-
model_select = gr.Radio(["v0-Q", "v0-F"], label="Model Selection", info="Q=Quality, F=Fidelity", value="v0-Q",
|
| 331 |
-
interactive=True)
|
| 332 |
|
| 333 |
with gr.Column():
|
| 334 |
gr.Markdown("<center>Restoring Output</center>")
|
|
@@ -340,14 +366,14 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 340 |
with gr.Column(visible=False):
|
| 341 |
llave_button = gr.Button(value="Generate description by LlaVa (disabled)")
|
| 342 |
with gr.Column():
|
| 343 |
-
diffusion_button = gr.Button(value="🚀 Upscale/Restore", variant = "primary")
|
| 344 |
with gr.Row():
|
| 345 |
with gr.Column():
|
| 346 |
-
param_setting = gr.Radio(["Quality", "Fidelity"], interactive=True, label="
|
| 347 |
with gr.Column():
|
| 348 |
-
restart_button = gr.Button(value="Apply
|
| 349 |
|
| 350 |
-
with gr.Accordion("Feedback", open=True):
|
| 351 |
fb_score = gr.Slider(label="Feedback Score", minimum=1, maximum=5, value=3, step=1,
|
| 352 |
interactive=True)
|
| 353 |
fb_text = gr.Textbox(label="Feedback Text", value="", placeholder='Please enter your feedback here.')
|
|
@@ -388,6 +414,7 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 388 |
fb_text
|
| 389 |
], queue = False, show_progress = False).success(fn=stage2_process, inputs = [
|
| 390 |
input_image,
|
|
|
|
| 391 |
prompt,
|
| 392 |
a_prompt,
|
| 393 |
n_prompt,
|
|
@@ -430,7 +457,8 @@ with gr.Blocks(title="SUPIR") as interface:
|
|
| 430 |
linear_CFG,
|
| 431 |
linear_s_stage2,
|
| 432 |
spt_linear_CFG,
|
| 433 |
-
spt_linear_s_stage2
|
|
|
|
| 434 |
])
|
| 435 |
|
| 436 |
submit_button.click(fn = submit_feedback, inputs = [
|
|
|
|
| 117 |
return captions[0]
|
| 118 |
|
| 119 |
@spaces.GPU(duration=240)
|
| 120 |
+
def stage2_process(
|
| 121 |
+
noisy_image,
|
| 122 |
+
denoise_image,
|
| 123 |
+
prompt,
|
| 124 |
+
a_prompt,
|
| 125 |
+
n_prompt,
|
| 126 |
+
num_samples,
|
| 127 |
+
upscale,
|
| 128 |
+
edm_steps,
|
| 129 |
+
s_stage1,
|
| 130 |
+
s_stage2,
|
| 131 |
+
s_cfg,
|
| 132 |
+
seed,
|
| 133 |
+
s_churn,
|
| 134 |
+
s_noise,
|
| 135 |
+
color_fix_type,
|
| 136 |
+
diff_dtype,
|
| 137 |
+
ae_dtype,
|
| 138 |
+
gamma_correction,
|
| 139 |
+
linear_CFG,
|
| 140 |
+
linear_s_stage2,
|
| 141 |
+
spt_linear_CFG,
|
| 142 |
+
spt_linear_s_stage2,
|
| 143 |
+
model_select
|
| 144 |
+
):
|
| 145 |
print('Start stage2_process')
|
| 146 |
if torch.cuda.device_count() == 0:
|
| 147 |
gr.Warning('Set this space to GPU config to make it work.')
|
| 148 |
return None, None
|
| 149 |
+
input_image = noisy_image if denoise_image is None else denoise_image
|
| 150 |
torch.cuda.set_device(SUPIR_device)
|
| 151 |
event_id = str(time.time_ns())
|
| 152 |
event_dict = {'event_id': event_id, 'localtime': time.ctime(), 'prompt': prompt, 'a_prompt': a_prompt,
|
|
|
|
| 207 |
print('Start load_and_reset')
|
| 208 |
if torch.cuda.device_count() == 0:
|
| 209 |
gr.Warning('Set this space to GPU config to make it work.')
|
| 210 |
+
return None, None, None, None, None, None, None, None, None, None, None, None, None, None
|
| 211 |
edm_steps = default_setting.edm_steps
|
| 212 |
s_stage2 = 1.0
|
| 213 |
s_stage1 = -1.0
|
|
|
|
| 226 |
if param_setting == "Quality":
|
| 227 |
s_cfg = default_setting.s_cfg_Quality
|
| 228 |
spt_linear_CFG = default_setting.spt_linear_CFG_Quality
|
| 229 |
+
model_select = "v0-Q"
|
| 230 |
elif param_setting == "Fidelity":
|
| 231 |
s_cfg = default_setting.s_cfg_Fidelity
|
| 232 |
spt_linear_CFG = default_setting.spt_linear_CFG_Fidelity
|
| 233 |
+
model_select = "v0-F"
|
| 234 |
else:
|
| 235 |
raise NotImplementedError
|
| 236 |
gr.Info('The parameters are reset.')
|
| 237 |
print('End load_and_reset')
|
| 238 |
return edm_steps, s_cfg, s_stage2, s_stage1, s_churn, s_noise, a_prompt, n_prompt, color_fix_type, linear_CFG, \
|
| 239 |
+
linear_s_stage2, spt_linear_CFG, spt_linear_s_stage2, model_select
|
| 240 |
|
| 241 |
|
| 242 |
def submit_feedback(event_id, fb_score, fb_text):
|
|
|
|
| 254 |
|
| 255 |
title_html = """
|
| 256 |
<h1><center>SUPIR</center></h1>
|
| 257 |
+
<big><center>Upscale your images up to x8 freely, without account, without watermark and download it</center></big>
|
| 258 |
<br/>
|
| 259 |
|
| 260 |
+
<p>SUPIR is a practicing model scaling for photo-realistic image restoration. It is still a research project under tested and is not yet a stable commercial product. LLaVa is not integrated in this demo. If you want to auto-generate the description of your image, use another <a href="https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b">LLaVa space</a>. The content added by SUPIR is imagination, not real-world information. The aim of SUPIR is the beauty and the illustration.
|
| 261 |
|
| 262 |
<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>
|
| 263 |
"""
|
|
|
|
| 306 |
qs = gr.Textbox(label="Question", info="Ask LLaVa what description you want", value="Describe the image and its style in a very detailed manner. The image is a realistic photography, not an art painting.", lines=3)
|
| 307 |
|
| 308 |
with gr.Accordion("Restoring options", open=False):
|
|
|
|
|
|
|
| 309 |
upscale = gr.Slider(label="Upscale factor", info="Resolution x1, x2, x3, x4, x5, x6, x7 or x8", minimum=1, maximum=8, value=2, step=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
a_prompt = gr.Textbox(label="Default Positive Prompt",
|
| 311 |
info="Describe what the image represents",
|
| 312 |
value='Cinematic, High Contrast, highly detailed, taken using a Canon EOS R '
|
|
|
|
| 321 |
'worst quality, low quality, frames, watermark, signature, jpeg artifacts, '
|
| 322 |
'deformed, lowres, over-smooth',
|
| 323 |
lines=3)
|
| 324 |
+
num_samples = gr.Slider(label="Num Samples", info="Number of generated results; I discourage to increase because the process is limited to 4 min", minimum=1, maximum=4 if not args.use_image_slider else 1
|
| 325 |
+
, value=1, step=1)
|
| 326 |
+
edm_steps = gr.Slider(label="Steps", info="lower=faster, higher=more details", minimum=1, maximum=200, value=default_setting.edm_steps if torch.cuda.device_count() > 0 else 1, step=1)
|
| 327 |
+
with gr.Row():
|
| 328 |
+
with gr.Column():
|
| 329 |
+
model_select = gr.Radio(["v0-Q", "v0-F"], label="Model Selection", info="Q=Quality, F=Fidelity", value="v0-Q",
|
| 330 |
+
interactive=True)
|
| 331 |
+
with gr.Column():
|
| 332 |
+
color_fix_type = gr.Radio(["None", "AdaIn", "Wavelet"], label="Color-Fix Type", info="AdaIn=Adaptive Instance Normalization, Wavelet=For JPEG artifacts", value="Wavelet",
|
| 333 |
+
interactive=True)
|
| 334 |
+
s_cfg = gr.Slider(label="Text Guidance Scale", info="lower=follow the image, higher=follow the prompt", minimum=1.0, maximum=15.0,
|
| 335 |
+
value=default_setting.s_cfg_Quality if torch.cuda.device_count() > 0 else 1.0, step=0.1)
|
| 336 |
+
s_stage2 = gr.Slider(label="Restoring Guidance Strength", minimum=0., maximum=1., value=1., step=0.05)
|
| 337 |
+
s_stage1 = gr.Slider(label="Pre-denoising Guidance Strength", minimum=-1.0, maximum=6.0, value=-1.0, step=1.0)
|
| 338 |
+
s_churn = gr.Slider(label="S-Churn", minimum=0, maximum=40, value=5, step=1)
|
| 339 |
+
s_noise = gr.Slider(label="S-Noise", minimum=1.0, maximum=1.1, value=1.003, step=0.001)
|
| 340 |
with gr.Row():
|
| 341 |
with gr.Column():
|
| 342 |
linear_CFG = gr.Checkbox(label="Linear CFG", value=True)
|
|
|
|
| 353 |
with gr.Column():
|
| 354 |
ae_dtype = gr.Radio(['fp32', 'bf16'], label="Auto-Encoder Data Type", value="bf16",
|
| 355 |
interactive=True)
|
| 356 |
+
randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed", value = True, info = "If checked, result is always different")
|
| 357 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, randomize=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
with gr.Column():
|
| 360 |
gr.Markdown("<center>Restoring Output</center>")
|
|
|
|
| 366 |
with gr.Column(visible=False):
|
| 367 |
llave_button = gr.Button(value="Generate description by LlaVa (disabled)")
|
| 368 |
with gr.Column():
|
| 369 |
+
diffusion_button = gr.Button(value="🚀 Upscale/Restore", variant = "primary", elem_id="process_button")
|
| 370 |
with gr.Row():
|
| 371 |
with gr.Column():
|
| 372 |
+
param_setting = gr.Radio(["Quality", "Fidelity"], interactive=True, label="Presetting", value="Quality")
|
| 373 |
with gr.Column():
|
| 374 |
+
restart_button = gr.Button(value="Apply presetting", scale=2)
|
| 375 |
|
| 376 |
+
with gr.Accordion("Feedback", open=True, visible=False):
|
| 377 |
fb_score = gr.Slider(label="Feedback Score", minimum=1, maximum=5, value=3, step=1,
|
| 378 |
interactive=True)
|
| 379 |
fb_text = gr.Textbox(label="Feedback Text", value="", placeholder='Please enter your feedback here.')
|
|
|
|
| 414 |
fb_text
|
| 415 |
], queue = False, show_progress = False).success(fn=stage2_process, inputs = [
|
| 416 |
input_image,
|
| 417 |
+
denoise_image,
|
| 418 |
prompt,
|
| 419 |
a_prompt,
|
| 420 |
n_prompt,
|
|
|
|
| 457 |
linear_CFG,
|
| 458 |
linear_s_stage2,
|
| 459 |
spt_linear_CFG,
|
| 460 |
+
spt_linear_s_stage2,
|
| 461 |
+
model_select
|
| 462 |
])
|
| 463 |
|
| 464 |
submit_button.click(fn = submit_feedback, inputs = [
|