Spaces:
Running
on
Zero
Running
on
Zero
model selection added, tiling forced to 2048
Browse files
app.py
CHANGED
|
@@ -4,36 +4,54 @@ from gradio_imageslider import ImageSlider
|
|
| 4 |
from image_gen_aux import UpscaleWithModel
|
| 5 |
from image_gen_aux.utils import load_image
|
| 6 |
|
|
|
|
|
|
|
| 7 |
|
| 8 |
@spaces.GPU
|
| 9 |
-
def upscale_image(image):
|
| 10 |
original = load_image(image)
|
| 11 |
|
| 12 |
-
upscaler = UpscaleWithModel.from_pretrained(
|
| 13 |
-
image = upscaler(original)
|
| 14 |
|
| 15 |
return original, image
|
| 16 |
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
gr.HTML(title)
|
| 22 |
with gr.Row():
|
| 23 |
with gr.Column():
|
| 24 |
input_image = gr.Image(type="pil", label="Input Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
run_button = gr.Button("Upscale")
|
| 26 |
with gr.Column():
|
| 27 |
result = ImageSlider(
|
| 28 |
interactive=False,
|
| 29 |
label="Generated Image",
|
| 30 |
-
elem_id="result-image",
|
| 31 |
-
position=0.1,
|
| 32 |
)
|
| 33 |
|
| 34 |
run_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
fn=upscale_image,
|
| 36 |
-
inputs=[input_image],
|
| 37 |
outputs=result,
|
| 38 |
)
|
| 39 |
|
|
|
|
| 4 |
from image_gen_aux import UpscaleWithModel
|
| 5 |
from image_gen_aux.utils import load_image
|
| 6 |
|
| 7 |
+
MODELS = {"UltraSharp": "OzzyGT/UltraSharp", "DAT X4": "OzzyGT/DAT_X4"}
|
| 8 |
+
|
| 9 |
|
| 10 |
@spaces.GPU
|
| 11 |
+
def upscale_image(image, model_selection):
|
| 12 |
original = load_image(image)
|
| 13 |
|
| 14 |
+
upscaler = UpscaleWithModel.from_pretrained(MODELS[model_selection]).to("cuda")
|
| 15 |
+
image = upscaler(original, tiling=True, tile_width=2048, tile_height=2048)
|
| 16 |
|
| 17 |
return original, image
|
| 18 |
|
| 19 |
|
| 20 |
+
def clear_result():
|
| 21 |
+
return gr.update(value=None)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
title = """<h1 align="center">Image Upscaler</h1>
|
| 25 |
+
<div align="center">This space is a showcase of the different super resolution models you can use to upscale with the
|
| 26 |
+
<a href="https://github.com/asomoza/image_gen_aux">Image Generation Auxiliary Tools</a> library.</div>
|
| 27 |
+
"""
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
gr.HTML(title)
|
| 31 |
with gr.Row():
|
| 32 |
with gr.Column():
|
| 33 |
input_image = gr.Image(type="pil", label="Input Image")
|
| 34 |
+
|
| 35 |
+
model_selection = gr.Dropdown(
|
| 36 |
+
choices=list(MODELS.keys()),
|
| 37 |
+
value="UltraSharp",
|
| 38 |
+
label="Model",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
run_button = gr.Button("Upscale")
|
| 42 |
with gr.Column():
|
| 43 |
result = ImageSlider(
|
| 44 |
interactive=False,
|
| 45 |
label="Generated Image",
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
run_button.click(
|
| 49 |
+
fn=clear_result,
|
| 50 |
+
inputs=None,
|
| 51 |
+
outputs=result,
|
| 52 |
+
).then(
|
| 53 |
fn=upscale_image,
|
| 54 |
+
inputs=[input_image, model_selection],
|
| 55 |
outputs=result,
|
| 56 |
)
|
| 57 |
|