AntaresGuo commited on
Commit
c3fcd5c
·
verified ·
1 Parent(s): c30cd3d

support gen word

Browse files
Files changed (1) hide show
  1. app.py +126 -53
app.py CHANGED
@@ -1,26 +1,32 @@
1
  import gradio as gr
2
 
3
  import numpy as np
4
- from interface_modules.X2Painting.template_config import style_example
5
  from interface_modules.X2Painting.client_process import send_to_server
6
 
7
 
8
- def on_select(evt: gr.SelectData):
9
  index = evt.index
10
  style_name = list(style_example.values())[index]
11
  return gr.update(value=style_name)
12
 
13
 
 
 
 
 
 
 
14
  css = """
15
  .gradio-container {background-color: #F0F5FF; width: 95% !important}
16
  """
17
  title = r"""
18
  </br>
19
- <h1 align="center" style="font-size: 42px;">Character2Painting</h1>
20
  </br>
21
 
22
  <br>
23
- <div style="text-align: center;">
24
  <h2>
25
  <span style="color: red;">Character</span> &lt;---
26
  <span style="color: black;">Zoom out </span>
@@ -30,63 +36,130 @@ title = r"""
30
  <span style="color: black;"> Zoom in ---&gt;</span>
31
  <span style="color: red;">Painting</span>
32
  </h2>
33
- </div>
34
- <br>
 
35
 
36
  </br>
37
- <img src="https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/xword_intro.png" style="display: block; margin: 0 auto; max-height: 384px;">
 
38
  </br>
39
  <h2 style="text-align: center;">===================🤪🥳 Have a Try 🤩😄===================</h2>
40
  """
41
-
 
 
42
  with gr.Blocks(css=css) as demo:
43
  # description
44
  gr.HTML(title)
45
- with gr.Row():
46
- with gr.Column(scale=1):
47
- gr.HTML("""
48
- <h1>⭐️ User Tips </h1>
49
- <h2> <p><b>step1:</b> Input a Character. Recommended Chinese Character.</p>
50
- <p><b>step2:</b> Select a style in the Gallery</p>
51
- <p><b>step3:</b> Click Run, Waiting for about 1 Min. Enjoy</p></h2>
52
- """)
53
- word = gr.Textbox(
54
- label="Input Character",
55
- info="please type Character, such as 李. (输入中文字,例如,李)",
56
- value="",
57
- elem_id="InputCha"
58
- )
59
-
60
- submit = gr.ClearButton(value="Run",elem_id="RunBtn")
61
- style_name = gr.Textbox(
62
- label="style_name",
63
- info="style_name",
64
- value="", visible=False,
65
- )
66
-
67
- with gr.Column(scale=6):
68
- gr.HTML("""
69
- <h1 align="center">Style Gallery</h1>
70
- """)
71
- example_gallery = gr.Gallery(label="style_type", show_label=True, elem_id="example_gallery",
72
- value=list(style_example.keys()), columns=5
73
- )
74
- # vis result gallery
75
- gr.HTML("""
76
- <h1 align="center">Result Gallery</h1>
77
- """)
78
- final_gallery = gr.Gallery(
79
- label="最终生成图",
80
- show_label=False,
81
- elem_classes="final_gallery",columns=[4], rows=[2]
82
- )
83
-
84
- submit.add([final_gallery])
85
- submit.click(send_to_server,
86
- inputs=[word, style_name],
87
- outputs=[final_gallery])
88
- example_gallery.select(on_select, None,
89
- [style_name])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  demo.queue()
92
  demo.launch(share=True)
 
1
  import gradio as gr
2
 
3
  import numpy as np
4
+ from interface_modules.X2Painting.template_config import style_example, style_example_word
5
  from interface_modules.X2Painting.client_process import send_to_server
6
 
7
 
8
+ def on_select_char(evt: gr.SelectData):
9
  index = evt.index
10
  style_name = list(style_example.values())[index]
11
  return gr.update(value=style_name)
12
 
13
 
14
+ def on_select_word(evt: gr.SelectData):
15
+ index = evt.index
16
+ style_name = list(style_example_word.values())[index]
17
+ return gr.update(value=style_name)
18
+
19
+
20
  css = """
21
  .gradio-container {background-color: #F0F5FF; width: 95% !important}
22
  """
23
  title = r"""
24
  </br>
25
+ <h1 align="center" style="font-size: 42px;">X2Painting</h1>
26
  </br>
27
 
28
  <br>
29
+ <div style="text-align: center;">
30
  <h2>
31
  <span style="color: red;">Character</span> &lt;---
32
  <span style="color: black;">Zoom out </span>
 
36
  <span style="color: black;"> Zoom in ---&gt;</span>
37
  <span style="color: red;">Painting</span>
38
  </h2>
39
+ </div>
40
+ <br>
41
+
42
 
43
  </br>
44
+ <img src="https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/x2painting_intro.png" style="display: block; margin: 0 auto; max-height: 384px;">
45
+
46
  </br>
47
  <h2 style="text-align: center;">===================🤪🥳 Have a Try 🤩😄===================</h2>
48
  """
49
+ # https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/x2painting_intro.png
50
+ # https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/xword_intro.png
51
+ # https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/loves.jpg
52
  with gr.Blocks(css=css) as demo:
53
  # description
54
  gr.HTML(title)
55
+ with gr.Tab("Character2Painting", elem_classes="CharTab") as Tab_Char:
56
+ with gr.Row():
57
+ with gr.Column(scale=1):
58
+ gr.HTML("""
59
+ <h1>⭐️ User Tips </h1>
60
+ <h2> <p><b>step1:</b> Input a Character.</p>
61
+ <p><b>step2:</b> Select a style in the Gallery</p>
62
+ <p><b>step3:</b> Click Run, Waiting for about 1 Min. Enjoy</p></h2>
63
+ """)
64
+ word_char = gr.Textbox(
65
+ label="Input Character",
66
+ info="please type Character, such as 李. (输入文字,例如,李)",
67
+ value="",
68
+ elem_id="InputCha"
69
+ )
70
+
71
+ submit_char = gr.ClearButton(value="RunChar", elem_id="RunBtnChar")
72
+ style_name_char = gr.Textbox(
73
+ label="style_name_char",
74
+ info="style_name_char",
75
+ value="", visible=False,
76
+ )
77
+
78
+ with gr.Column(scale=6):
79
+ gr.HTML("""
80
+ <h1 align="center">Style Gallery</h1>
81
+ """)
82
+ example_gallery_char = gr.Gallery(label="style_type_char", show_label=True,
83
+ elem_id="example_gallery_char",
84
+ value=list(style_example.keys()), columns=10
85
+ )
86
+ # vis result gallery
87
+ gr.HTML("""
88
+ <h1 align="center">Result Gallery</h1>
89
+ """)
90
+ final_gallery_char = gr.Gallery(
91
+ label="最终生成图",
92
+ show_label=False,
93
+ elem_classes="final_gallery_char", columns=[4], rows=[2]
94
+ )
95
+
96
+ submit_char.add([final_gallery_char])
97
+ submit_char.click(send_to_server,
98
+ inputs=[word_char, style_name_char],
99
+ outputs=[final_gallery_char])
100
+ example_gallery_char.select(on_select_char, None,
101
+ [style_name_char])
102
+ with gr.Tab("Word2Painting", elem_classes="WordTab") as Tab_Word:
103
+ with gr.Row():
104
+ with gr.Column(scale=1):
105
+ gr.HTML("""
106
+ <h1>⭐️ User Tips </h1>
107
+ <h2> <p><b>step1:</b> Input a word. Max length: 4 for Chinese and 9 for English. </p>
108
+ <p><b>step2:</b> Select a style in the Gallery</p>
109
+ <p><b>step3:</b> Click Run, Waiting for about 1 Min. Enjoy</p></h2>
110
+ """)
111
+ word_word = gr.Textbox(
112
+ label="Input Word",
113
+ info="please type Word, such as 暴富. (输入词语,例如,暴富)",
114
+ value="暴富",
115
+ elem_id="InputWord"
116
+ )
117
+
118
+ submit_word = gr.ClearButton(value="RunWord", elem_id="RunBtnWord")
119
+ style_name_word = gr.Textbox(
120
+ label="style_name_word",
121
+ info="style_name_word",
122
+ value="", visible=False,
123
+ )
124
+
125
+ with gr.Column(scale=6):
126
+ gr.HTML("""
127
+ <h1 align="center">Style Gallery</h1>
128
+ """)
129
+ example_gallery_word = gr.Gallery(label="style_type_word", show_label=True,
130
+ elem_id="example_gallery_word",
131
+ value=list(style_example_word.keys()), columns=5,
132
+ allow_preview=True, selected_index=0,
133
+ preview=True,
134
+ object_fit="scale-down",
135
+ )
136
+ # vis result gallery
137
+ gr.HTML("""
138
+ <h1 align="center">Result Gallery</h1>
139
+ """)
140
+ final_gallery_word = gr.Gallery(
141
+ label="最终生成图",
142
+ show_label=False,
143
+ elem_classes="final_gallery", columns=1,
144
+ allow_preview=True, selected_index=0,
145
+ preview=True,
146
+ object_fit="scale-down",
147
+ )
148
+
149
+ submit_word.add([final_gallery_word])
150
+ submit_word.click(send_to_server,
151
+ inputs=[word_word, style_name_word],
152
+ outputs=[final_gallery_word])
153
+ example_gallery_word.select(on_select_word, None,
154
+ [style_name_word])
155
+
156
+ with gr.Tab("X2Painting", elem_classes="XTab") as Tab_X:
157
+ gr.HTML("""
158
+ <h1 align="center">Give me some time to train the model</h1>
159
+ </br>
160
+ <img src="https://raw.githubusercontent.com/antarestcguo/X2Painting/main/resources/loves.jpg" style="display: block; margin: 0 auto; max-height: 384px;">
161
+ </br>
162
+ """)
163
 
164
  demo.queue()
165
  demo.launch(share=True)