Spaces:
Paused
Paused
Fabrice-TIERCELIN
commited on
Commit
•
20d2752
1
Parent(s):
a35ddd5
, type="filepath"
Browse files
app.py
CHANGED
@@ -86,7 +86,7 @@ def stage1_process(
|
|
86 |
gr.Warning('Set this space to GPU config to make it work.')
|
87 |
return None, None
|
88 |
torch.cuda.set_device(SUPIR_device)
|
89 |
-
LQ = HWC3(input_image)
|
90 |
LQ = fix_resize(LQ, 512)
|
91 |
# stage1
|
92 |
LQ = np.array(LQ) / 255 * 2 - 1
|
@@ -187,19 +187,19 @@ def stage2_process(
|
|
187 |
a_prompt = prompt + a_prompt
|
188 |
print("Final prompt: " + str(a_prompt))
|
189 |
|
190 |
-
|
191 |
|
192 |
if rotation == 90:
|
193 |
-
|
194 |
elif rotation == 180:
|
195 |
-
|
196 |
-
|
197 |
elif rotation == -90:
|
198 |
-
|
199 |
|
200 |
if 1 < downscale:
|
201 |
-
input_height, input_width, input_channel =
|
202 |
-
|
203 |
|
204 |
# Allocation
|
205 |
if allocation == 1:
|
@@ -284,8 +284,8 @@ def restore_in_10min(*args, **kwargs):
|
|
284 |
return restore(*args, **kwargs)
|
285 |
|
286 |
def restore(
|
|
|
287 |
input_image,
|
288 |
-
denoise_image,
|
289 |
prompt,
|
290 |
a_prompt,
|
291 |
n_prompt,
|
@@ -467,10 +467,10 @@ with gr.Blocks() as interface:
|
|
467 |
""")
|
468 |
gr.HTML(title_html)
|
469 |
|
470 |
-
input_image = gr.Image(label="Input (*.png, *.webp, *.jpeg, *.gif, *.bmp)", show_label=True, type="
|
471 |
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, interactive=True, visible=False)
|
472 |
with gr.Group():
|
473 |
-
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;
|
474 |
prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b'"'>LlaVa space</a> to auto-generate the description of your image.")
|
475 |
upscale = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8]], label="Upscale factor", info="Resolution x1 to x8", value=2, interactive=True)
|
476 |
allocation = gr.Radio([["1 min", 1], ["2 min", 2], ["3 min", 3], ["4 min", 4], ["5 min", 5], ["6 min", 6], ["7 min", 7], ["8 min", 8]], label="GPU allocation time", info="lower=May abort run, higher=Quota penalty for next runs", value=6, interactive=True)
|
@@ -479,7 +479,7 @@ with gr.Blocks() as interface:
|
|
479 |
with gr.Accordion("Pre-denoising (optional)", open=False):
|
480 |
gamma_correction = gr.Slider(label="Gamma Correction", info = "lower=lighter, higher=darker", minimum=0.1, maximum=2.0, value=1.0, step=0.1)
|
481 |
denoise_button = gr.Button(value="Pre-denoise")
|
482 |
-
denoise_image = gr.Image(label="Denoised image", show_label=True, type="
|
483 |
denoise_information = gr.HTML(value="If present, the denoised image will be used for the restoration instead of the input image.", visible=False)
|
484 |
|
485 |
with gr.Accordion("Advanced options", open=False):
|
@@ -618,7 +618,7 @@ with gr.Blocks() as interface:
|
|
618 |
"./Examples/Example2.jpeg",
|
619 |
0,
|
620 |
None,
|
621 |
-
"
|
622 |
"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.",
|
623 |
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, bokeh, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
624 |
1,
|
|
|
86 |
gr.Warning('Set this space to GPU config to make it work.')
|
87 |
return None, None
|
88 |
torch.cuda.set_device(SUPIR_device)
|
89 |
+
LQ = HWC3(Image.open(input_image))
|
90 |
LQ = fix_resize(LQ, 512)
|
91 |
# stage1
|
92 |
LQ = np.array(LQ) / 255 * 2 - 1
|
|
|
187 |
a_prompt = prompt + a_prompt
|
188 |
print("Final prompt: " + str(a_prompt))
|
189 |
|
190 |
+
denoise_image = Image.open(noisy_image if denoise_image is None else denoise_image)
|
191 |
|
192 |
if rotation == 90:
|
193 |
+
denoise_image = np.array(list(zip(*denoise_image[::-1])))
|
194 |
elif rotation == 180:
|
195 |
+
denoise_image = np.array(list(zip(*denoise_image[::-1])))
|
196 |
+
denoise_image = np.array(list(zip(*denoise_image[::-1])))
|
197 |
elif rotation == -90:
|
198 |
+
denoise_image = np.array(list(zip(*denoise_image))[::-1])
|
199 |
|
200 |
if 1 < downscale:
|
201 |
+
input_height, input_width, input_channel = denoise_image.shape
|
202 |
+
denoise_image = denoise_image.resize((input_width // downscale, input_height // downscale), Image.LANCZOS)
|
203 |
|
204 |
# Allocation
|
205 |
if allocation == 1:
|
|
|
284 |
return restore(*args, **kwargs)
|
285 |
|
286 |
def restore(
|
287 |
+
noisy_image,
|
288 |
input_image,
|
|
|
289 |
prompt,
|
290 |
a_prompt,
|
291 |
n_prompt,
|
|
|
467 |
""")
|
468 |
gr.HTML(title_html)
|
469 |
|
470 |
+
input_image = gr.Image(label="Input (*.png, *.webp, *.jpeg, *.gif, *.bmp)", show_label=True, type="filepath", height=600, elem_id="image-input")
|
471 |
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, interactive=True, visible=False)
|
472 |
with gr.Group():
|
473 |
+
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)
|
474 |
prompt_hint = gr.HTML("You can use a <a href='"'https://huggingface.co/spaces/MaziyarPanahi/llava-llama-3-8b'"'>LlaVa space</a> to auto-generate the description of your image.")
|
475 |
upscale = gr.Radio([["x1", 1], ["x2", 2], ["x3", 3], ["x4", 4], ["x5", 5], ["x6", 6], ["x7", 7], ["x8", 8]], label="Upscale factor", info="Resolution x1 to x8", value=2, interactive=True)
|
476 |
allocation = gr.Radio([["1 min", 1], ["2 min", 2], ["3 min", 3], ["4 min", 4], ["5 min", 5], ["6 min", 6], ["7 min", 7], ["8 min", 8]], label="GPU allocation time", info="lower=May abort run, higher=Quota penalty for next runs", value=6, interactive=True)
|
|
|
479 |
with gr.Accordion("Pre-denoising (optional)", open=False):
|
480 |
gamma_correction = gr.Slider(label="Gamma Correction", info = "lower=lighter, higher=darker", minimum=0.1, maximum=2.0, value=1.0, step=0.1)
|
481 |
denoise_button = gr.Button(value="Pre-denoise")
|
482 |
+
denoise_image = gr.Image(label="Denoised image", show_label=True, type="filepath", sources=[], height=600, elem_id="image-s1")
|
483 |
denoise_information = gr.HTML(value="If present, the denoised image will be used for the restoration instead of the input image.", visible=False)
|
484 |
|
485 |
with gr.Accordion("Advanced options", open=False):
|
|
|
618 |
"./Examples/Example2.jpeg",
|
619 |
0,
|
620 |
None,
|
621 |
+
"La cabeza de un gato atigrado, en una casa, fotorrealista, 8k, extremadamente detallada",
|
622 |
"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.",
|
623 |
"painting, oil painting, illustration, drawing, art, sketch, anime, cartoon, CG Style, 3D render, unreal engine, blurring, bokeh, ugly, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
|
624 |
1,
|