File size: 3,864 Bytes
1a3227d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
96
97
import gradio as gr
from gradio_client import Client

clientGFPGAN = Client("leonelhs/GFPGAN")
clientZeroScratches = Client("leonelhs/ZeroScratches")
clientDeoldify = Client("leonelhs/deoldify")
clientEnhanceLight = Client("leonelhs/Zero-DCE")
clientZeroBackground = Client("leonelhs/ZeroBackground")
clientFaceParser = Client("leonelhs/faceparser")


def enhance_face(image):
    return clientGFPGAN.predict(image, "v1.4", "2", api_name="/predict")[1]


def zero_scratches(image):
    return clientZeroScratches.predict(image, api_name="/predict")


def colorize_photo(image):
    return clientDeoldify.predict(image, api_name="/predict")


def enhance_light(image):
    return clientEnhanceLight.predict(image, api_name="/predict")


def zero_background(image, new_bgr):
    return clientZeroBackground.predict(image, new_bgr, api_name="/predict")


def parse_face(image):
    return clientFaceParser.predict(image, api_name="/predict")


def mirror(x):
    return x


footer = r"""
<center>
<p>This App is running on a CPU, help us to upgrade a GPU or just give us a <a href='https://github.com/leonelhs/face-shine' target='_blank'>Github ⭐</a></p>
</br>
<a href="https://www.buymeacoffee.com/leonelhs">
    <img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=leonelhs&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" />
</a>
</center>
</br>
<center><span>[email protected]</span></center>
"""

with gr.Blocks() as app:
    with gr.Tab("Face Shine"):
        with gr.Row():
            with gr.Column(scale=1):
                btn_hires = gr.Button(value="Enhance resolution")
                btn_eraser = gr.Button(value="Erase scratches")
                btn_color = gr.Button(value="Colorize photo")
                btn_light = gr.Button(value="Enhance light")
                with gr.Accordion("Clear background", open=False):
                    btn_clear = gr.Button(value="Clear background")
                    # chk_newbgr = gr.Checkbox(label="Change background")
                    img_newbgr = gr.Image(label="Choose file for new background", type="filepath")

            with gr.Column(scale=4):
                with gr.Row():
                    img_input = gr.Image(label="Input", type="filepath")
                    img_output = gr.Image(label="Result", type="filepath", interactive=False)

                with gr.Row():
                    btn_swap = gr.Button(value="Swap images")
                    btn_reset = gr.Button("Clear")

                btn_hires.click(enhance_face, inputs=[img_input], outputs=[img_output])
                btn_eraser.click(zero_scratches, inputs=[img_input], outputs=[img_output])
                btn_color.click(colorize_photo, inputs=[img_input], outputs=[img_output])
                btn_light.click(enhance_light, inputs=[img_input], outputs=[img_output])
                btn_clear.click(zero_background, inputs=[img_input, img_newbgr], outputs=[img_output])
                btn_swap.click(mirror, inputs=[img_output], outputs=[img_input])
                btn_reset.click(lambda: None, None, img_input, queue=False)

    with gr.Tab("Settings"):
        with gr.Accordion("Real-ESRGAN: Practical Image/Video Restoration. ", open=False):
            gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", label='version')
        with gr.Accordion("GFPGAN: Practical Face Restoration Algorithm", open=False):
            gr.Checkbox(label="Include false", info="Extra process for face enhancement")
            gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", label='version')
            gr.Dropdown(
                ["1", "2", "3", "4"], label="Scale", info="Select output scale"
            )
        gr.Button("Save settings")

    with gr.Row():
        gr.HTML(footer)

app.launch()