File size: 3,708 Bytes
09fb9f0
5941390
d127695
5941390
 
 
791c7ad
 
 
9712a0e
791c7ad
9712a0e
8346ea0
654b939
cc743a2
0f9d535
a81cbf3
 
3d6cfb3
27c9e62
61a462b
6d5c083
 
 
cd8741c
5d625fa
 
a81cbf3
4a4fe3a
27c9e62
4a4fe3a
7a21c88
 
3d6cfb3
a81cbf3
654b939
8cff209
3d6cfb3
 
 
8346ea0
383c5b7
5941390
 
383c5b7
5941390
 
383c5b7
d670e90
5941390
 
 
 
383c5b7
 
 
 
 
791c7ad
c2c49d6
417a371
383c5b7
09fb9f0
d127695
5941390
d127695
 
 
383c5b7
 
 
0f9d535
383c5b7
 
 
66eaf5f
d127695
 
66eaf5f
 
d127695
66eaf5f
5941390
383c5b7
 
 
 
5941390
383c5b7
5941390
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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

# This uses https://github.com/asomoza/image_gen_aux/blob/main/src/image_gen_aux/upscalers/README.md
# Also this space has been duplicated from their official huggingface space, https://huggingface.co/spaces/OzzyGT/basic_upscaler
# They did great work, and I was happy to see them to also use my models :) I thought Id duplicate it and extend it.
# It basically made me get a pro account so I can make a Zero GPU space and made me upload a lot of my models on huggingface now so I can use them here ;)

# My models
MODELS = {
    "4xNomos2_hq_drct-l": "Phips/4xNomos2_hq_drct-l",
    "4xNomosWebPhoto_RealPLKSR": "Phips/4xNomosWebPhoto_RealPLKSR",
    "4xRealWebPhoto_v4_dat2": "Phips/4xRealWebPhoto_v4_dat2",
    "4xRealWebPhoto_v3_atd": "Phips/4xRealWebPhoto_v3_atd",
    "4xNomos8k_atd_jpg": "Phips/4xNomos8k_atd_jpg",
    "4xNomosUni_rgt_multijpg": "Phips/4xNomosUni_rgt_multijpg",
    "4xLSDIRDAT": "Phips/4xLSDIRDAT",
    "4xSSDIRDAT": "Phips/4xSSDIRDAT",
    "4xNomos8kHAT-L_otf": "Phips/4xNomos8kHAT-L_otf",
    "4xNomosUniDAT_otf": "Phips/4xNomosUniDAT_otf",
    "4xNomosUniDAT_bokeh_jpg": "Phips/4xNomosUniDAT_bokeh_jpg",
    "4xNomos8kSCHAT-L": "Phips/4xNomos8kSCHAT-L",
    "4xFFHQDAT": "Phips/4xFFHQDAT",
    "4xFaceUpDAT": "Phips/4xFaceUpDAT",
    "4xTextures_GTAV_rgt-s_dither": "Phips/4xTextures_GTAV_rgt-s_dither",
    "4xTextureDAT2_otf": "Phips/4xTextureDAT2_otf",
    "4xLexicaDAT2_otf": "Phips/4xLexicaDAT2_otf",
    "2xHFA2k_LUDVAE_compact": "Phips/2xHFA2k_LUDVAE_compact",
    "2xHFA2kAVCCompact": "Phips/2xHFA2kAVCCompact",
    "2xHFA2kCompact": "Phips/2xHFA2kCompact",
    "2xEvangelion_dat2": "Phips/2xEvangelion_dat2",
    "1xDeJPG_realplksr_otf": "Phips/1xDeJPG_realplksr_otf",
    "1xDeH264_realplksr": "Phips/1xDeH264_realplksr",
    "1xDeNoise_realplksr_otf": "Phips/1xDeNoise_realplksr_otf",
    "1xExposureCorrection_compact": "Phips/1xExposureCorrection_compact",
    "1xUnderExposureCorrection_compact": "Phips/1xUnderExposureCorrection_compact",
    "1xOverExposureCorrection_compact": "Phips/1xOverExposureCorrection_compact",
}


@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> 
This space makes use of <a href="https://github.com/Phhofm/models">my self trained models</a> and makes use of tiling at 1024x1024</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)