File size: 2,867 Bytes
4ec2f90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from codeformer.app import inference_app


class CodeformerUpscalerGenerator:
    def generate_image(
        self,
        image_path: str,
        background_enhance: bool,
        face_upsample: bool,
        upscale: int,
        codeformer_fidelity: int,
    ):

        pipe = inference_app(
            image=image_path,
            background_enhance=background_enhance,
            face_upsample=face_upsample,
            upscale=upscale,
            codeformer_fidelity=codeformer_fidelity,
        )

        return [pipe]

    def app():
        with gr.Blocks():
            with gr.Row():
                with gr.Column():
                    codeformer_upscale_image_file = gr.Image(
                        type="filepath", label="Image"
                    ).style(height=260)

                    with gr.Row():
                        with gr.Column():
                            codeformer_face_upsample = gr.Checkbox(
                                label="Face Upsample",
                                value=True,
                            )
                            codeformer_upscale = gr.Slider(
                                label="Upscale",
                                minimum=1,
                                maximum=4,
                                step=1,
                                value=2,
                            )
                        with gr.Row():
                            with gr.Column():
                                codeformer_background_enhance = gr.Checkbox(
                                    label="Background Enhance",
                                    value=True,
                                )
                                codeformer_upscale_fidelity = gr.Slider(
                                    label="Codeformer Fidelity",
                                    minimum=0.1,
                                    maximum=1.0,
                                    step=0.1,
                                    value=0.5,
                                )

                    codeformer_upscale_predict_button = gr.Button(
                        value="Generator"
                    )

                with gr.Column():
                    output_image = gr.Gallery(
                        label="Generated images",
                        show_label=False,
                        elem_id="gallery",
                    ).style(grid=(1, 2))

        codeformer_upscale_predict_button.click(
            fn=CodeformerUpscalerGenerator().generate_image,
            inputs=[
                codeformer_upscale_image_file,
                codeformer_background_enhance,
                codeformer_face_upsample,
                codeformer_upscale,
                codeformer_upscale_fidelity,
            ],
            outputs=[output_image],
        )