File size: 6,925 Bytes
743cef3
 
 
c3fcd5c
743cef3
 
 
c3fcd5c
743cef3
 
 
 
 
c3fcd5c
 
 
 
 
 
743cef3
 
 
 
 
c3fcd5c
e51d216
 
 
c3fcd5c
e51d216
 
 
 
 
ef96746
e51d216
 
ef96746
c3fcd5c
 
 
743cef3
 
c3fcd5c
 
743cef3
 
 
c3fcd5c
 
 
743cef3
 
 
c3fcd5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743cef3
 
2758916
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import gradio as gr

import numpy as np
from interface_modules.X2Painting.template_config import style_example, style_example_word
from interface_modules.X2Painting.client_process import send_to_server


def on_select_char(evt: gr.SelectData):
    index = evt.index
    style_name = list(style_example.values())[index]
    return gr.update(value=style_name)


def on_select_word(evt: gr.SelectData):
    index = evt.index
    style_name = list(style_example_word.values())[index]
    return gr.update(value=style_name)


css = """
        .gradio-container {background-color: #F0F5FF; width: 95% !important}
        """
title = r"""
    </br>
    <h1 align="center" style="font-size: 42px;">X2Painting</h1>
    </br>
    
    <br>
<div style="text-align: center;">
    <h2>
        <span style="color: red;">Character</span> &lt;---
        <span style="color: black;">Zoom out </span>
        <a href='https://github.com/antarestcguo/X2Painting' target="_blank" style="display: inline-block; text-decoration: none; color: black; vertical-align: middle;">
            <img src='https://img.shields.io/badge/Github-Repo-blue' alt="GitHub" style="width: auto; height: 20px;">
        </a>
        <span style="color: black;"> Zoom in ---&gt;</span>
        <span style="color: red;">Painting</span>
    </h2>
</div>
<br>
    

    </br>   
    <img src="https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/x2painting_intro.png" style="display: block; margin: 0 auto; max-height: 384px;">
    
    </br>
    <h2 style="text-align: center;">===================🤪🥳 Have a Try 🤩😄===================</h2>
    """
# https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/x2painting_intro.png
# https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/xword_intro.png
# https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/loves.jpg
with gr.Blocks(css=css) as demo:
    # description
    gr.HTML(title)
    with gr.Tab("Character2Painting", elem_classes="CharTab") as Tab_Char:
        with gr.Row():
            with gr.Column(scale=1):
                gr.HTML("""
                    <h1>⭐️ User Tips </h1>
                    <h2> <p><b>step1:</b> Input a Character.</p>
                    <p><b>step2:</b> Select a style in the Gallery</p>
                    <p><b>step3:</b> Click Run, Waiting for about 1 Min. Enjoy</p></h2>
                """)
                word_char = gr.Textbox(
                    label="Input Character",
                    info="please type Character, such as 李. (输入文字,例如,李)",
                    value="李",
                    elem_id="InputCha"
                )

                submit_char = gr.ClearButton(value="RunChar", elem_id="RunBtnChar")
                style_name_char = gr.Textbox(
                    label="style_name_char",
                    info="style_name_char",
                    value="", visible=False,
                )

            with gr.Column(scale=6):
                gr.HTML("""
                <h1 align="center">Style Gallery</h1>
                """)
                example_gallery_char = gr.Gallery(label="style_type_char", show_label=True,
                                                  elem_id="example_gallery_char",
                                                  value=list(style_example.keys()), columns=10
                                                  )
        # vis result gallery
        gr.HTML("""
        <h1 align="center">Result Gallery</h1>
        """)
        final_gallery_char = gr.Gallery(
            label="最终生成图",
            show_label=False,
            elem_classes="final_gallery_char", columns=[4], rows=[2]
        )

        submit_char.add([final_gallery_char])
        submit_char.click(send_to_server,
                          inputs=[word_char, style_name_char],
                          outputs=[final_gallery_char])
        example_gallery_char.select(on_select_char, None,
                                    [style_name_char])
    with gr.Tab("Word2Painting", elem_classes="WordTab") as Tab_Word:
        with gr.Row():
            with gr.Column(scale=1):
                gr.HTML("""
                    <h1>⭐️ User Tips </h1>
                    <h2> <p><b>step1:</b> Input a word. Max length: 4 for Chinese and 9 for English. </p>
                    <p><b>step2:</b> Select a style in the Gallery</p>
                    <p><b>step3:</b> Click Run, Waiting for about 1 Min. Enjoy</p></h2>
                """)
                word_word = gr.Textbox(
                    label="Input Word",
                    info="please type Word, such as 暴富. (输入词语,例如,暴富)",
                    value="暴富",
                    elem_id="InputWord"
                )

                submit_word = gr.ClearButton(value="RunWord", elem_id="RunBtnWord")
                style_name_word = gr.Textbox(
                    label="style_name_word",
                    info="style_name_word",
                    value="", visible=False,
                )

            with gr.Column(scale=6):
                gr.HTML("""
                <h1 align="center">Style Gallery</h1>
                """)
                example_gallery_word = gr.Gallery(label="style_type_word", show_label=True,
                                                  elem_id="example_gallery_word",
                                                  value=list(style_example_word.keys()), columns=5,
                                                  allow_preview=True, selected_index=0,
                                                  preview=True,
                                                  object_fit="scale-down",
                                                  )
        # vis result gallery
        gr.HTML("""
        <h1 align="center">Result Gallery</h1>
        """)
        final_gallery_word = gr.Gallery(
            label="最终生成图",
            show_label=False,
            elem_classes="final_gallery", columns=1,
            allow_preview=True, selected_index=0,
            preview=True,
            object_fit="scale-down",
        )

        submit_word.add([final_gallery_word])
        submit_word.click(send_to_server,
                          inputs=[word_word, style_name_word],
                          outputs=[final_gallery_word])
        example_gallery_word.select(on_select_word, None,
                                    [style_name_word])

    with gr.Tab("X2Painting", elem_classes="XTab") as Tab_X:
        gr.HTML("""
        <h1 align="center">Give me some time to train the model</h1>
    </br>
    <img src="https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/loves.jpg" style="display: block; margin: 0 auto; max-height: 384px;">
    </br>
                        """)

demo.queue()
demo.launch(share=True)