|
import gradio as gr |
|
import spaces |
|
from gradio_imageslider import ImageSlider |
|
from image_gen_aux import UpscaleWithModel |
|
from image_gen_aux.utils import load_image |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MODELS = { |
|
"4xNomos2_hq_drct-l": "Phips/4xNomos2_hq_drct-l", |
|
"4xNomosWebPhoto_RealPLKSR": "OzzyGT/4xNomosWebPhoto_RealPLKSR", |
|
"4xRealWebPhoto_v4_dat2": "Phips/4xRealWebPhoto_v4_dat2", |
|
"1xDeH264_realplksr": "Phips/1xDeH264_realplksr", |
|
} |
|
|
|
|
|
@spaces.GPU |
|
def upscale_image(image, model_selection): |
|
original = load_image(image) |
|
|
|
upscaler = UpscaleWithModel.from_pretrained(MODELS[model_selection]).to("cuda") |
|
image = upscaler(original, tiling=True, tile_width=1024, tile_height=1024) |
|
|
|
return original, image |
|
|
|
|
|
def clear_result(): |
|
return gr.update(value=None) |
|
|
|
|
|
title = """<h1 align="center">Image Upscaler</h1> |
|
<div align="center">Use this Space to upscale your images, makes use of the |
|
<a href="https://github.com/asomoza/image_gen_aux">Image Generation Auxiliary Tools</a> library. <br> For now makes use of my self trained models, but can be extended to more models from other authors if they message me.</div> |
|
""" |
|
|
|
with gr.Blocks() as demo: |
|
gr.HTML(title) |
|
with gr.Row(): |
|
with gr.Column(): |
|
input_image = gr.Image(type="pil", label="Input Image") |
|
|
|
model_selection = gr.Dropdown( |
|
choices=list(MODELS.keys()), |
|
value="4xNomos2_hq_drct-l", |
|
label="Model", |
|
) |
|
|
|
run_button = gr.Button("Upscale") |
|
with gr.Column(): |
|
result = ImageSlider( |
|
interactive=False, |
|
label="Generated Image", |
|
) |
|
|
|
run_button.click( |
|
fn=clear_result, |
|
inputs=None, |
|
outputs=result, |
|
).then( |
|
fn=upscale_image, |
|
inputs=[input_image, model_selection], |
|
outputs=result, |
|
) |
|
|
|
|
|
demo.launch(share=False) |
|
|