Li commited on
Commit
743cef3
1 Parent(s): 65d6848
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea/
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <h2 align="center"> <span style="color: red;">Character</span> <--- <span style="color: black;">Zoom out⭐️⭐⭐⭐⭐Zoom in ---> </span> <span style="color: red;">Painting</span></h2>
21
+ </br>
22
+
23
+ </br>
24
+ <img src="file/docs/resource/X2Painting/pics/xword_intro.png" style="display: block; margin: 0 auto; max-height: 384px;">
25
+ </br>
26
+ <h2 style="text-align: center;">===================🤪🥳 Have a Try 🤩😄===================</h2>
27
+ """
28
+
29
+ with gr.Blocks(css=css) as demo:
30
+ # description
31
+ gr.HTML(title)
32
+ with gr.Row():
33
+ with gr.Column():
34
+ # with gr.Row(scale=1):
35
+ # with gr.Column():
36
+ gr.Markdown('''
37
+ ⭐️<b> User Tips </b>
38
+ - <b>step1:</b>Input a Character. Recommended Chinese Character.
39
+ - <b>step2:</b>Select a style in the Gallery
40
+ - <b>step3:</b>Click Run,Waiting for about 1 Min. Enjoy
41
+ ''')
42
+ word = gr.Textbox(
43
+ label="Input Character",
44
+ info="please type Character, such as 李. (输入中文字,例如,李)",
45
+ value="李",
46
+ elem_id="InputCha"
47
+ )
48
+
49
+ submit = gr.ClearButton(value="Run",elem_id="RunBtn")
50
+ style_name = gr.Textbox(
51
+ label="style_name",
52
+ info="style_name",
53
+ value="", visible=False,
54
+ )
55
+
56
+ with gr.Column(scale=6):
57
+ gr.Markdown('''
58
+ <h1 align="center">Style Gallery</h1>
59
+ ''')
60
+ example_gallery = gr.Gallery(label="style_type", show_label=True, elem_id="example_gallery",
61
+ value=list(style_example.keys()), columns=10
62
+ )
63
+ # vis result gallery
64
+ gr.Markdown('''
65
+ <h1 align="center">Result Gallery</h1>
66
+ ''')
67
+ final_gallery = gr.Gallery(
68
+ label="最终生成图(paintings),第一行:refine后生成结果,第二行:初始生成结果,第三行:refine前的文字增强处理图",
69
+ show_label=False,
70
+ elem_classes="final_gallery",
71
+ ).style(columns=[4], rows=[2])
72
+
73
+ # server_port = gr.Number(value=args.server_port, visible=False)
74
+ submit.add([final_gallery])
75
+ submit.click(send_to_server,
76
+ inputs=[word, style_name],
77
+ outputs=[final_gallery])
78
+ example_gallery.select(on_select, None,
79
+ [style_name])
80
+
81
+ demo.queue()
82
+ demo.launch(share=True, server_name="0.0.0.0", server_port=12404)
83
+ # demo.launch(share=True)
interface_modules/X2Painting/__init__.py ADDED
File without changes
interface_modules/X2Painting/client_process.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio
2
+
3
+ import interface_modules.X2Painting.server_config as server_config
4
+ import json
5
+ import requests
6
+ from utils.data_convert import base64_to_image
7
+ from interface_modules.WordArt.template_config import font_style_dict
8
+
9
+
10
+ def send_to_server(word, style_name):
11
+ send_data = server_config.send_data.copy()
12
+ # fill send_data
13
+ send_data["gen_num"] = 4 #
14
+
15
+ # task specific
16
+ send_data['extra_input_infor'] = {
17
+ 'WordArt':
18
+ {
19
+ "style": style_name,
20
+ "word": word,
21
+ }
22
+ }
23
+
24
+ # prepare to send
25
+ post_addr = server_config.post_addr
26
+ json_data = json.dumps(send_data)
27
+ response = requests.post(post_addr, data=json_data, headers=server_config.headers)
28
+
29
+ # process feed back images
30
+ if response.status_code != 200:
31
+ print("post error")
32
+ return [None]
33
+
34
+ print("HF XPainting post sucess, process image")
35
+ result_dict = json.loads(response.text)
36
+ if result_dict.get("error_code") != 0:
37
+ print("error", "-" * 30)
38
+ print(result_dict["infor"])
39
+ gradio.Error(result_dict["infor"])
40
+ return [None]
41
+
42
+ result_img_list = result_dict["image"]
43
+ enhance_output = []
44
+ loop1_output = []
45
+ for i, img_obj in enumerate(result_img_list):
46
+ final_img = base64_to_image(img_obj["image"]) # 最终结果图片 PIL格式
47
+ enhance_output.append((final_img, "{}_{}_enhance.jpg".format(word, i)))
48
+
49
+ if "loop1_images" in img_obj['extra_image']:
50
+ loop1_images = img_obj['extra_image']["loop1_images"]
51
+ img = base64_to_image(loop1_images)
52
+ loop1_output.append((img, "{}_{}_loop1_images.jpg".format(word, i)))
53
+
54
+ return enhance_output + loop1_output
interface_modules/X2Painting/server_config.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ post_addr = ""
2
+
3
+ send_data = {}
4
+ send_data["task_type"] = "gen_WordArt"
5
+ send_data["visual_id"] = "-1"
6
+
7
+ headers = {'Content-Type': 'application/json'}
interface_modules/X2Painting/template_config.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ style_example = {
2
+ "./docs/resource/X2Painting/gradio_examples/01_te.jpg": "butterflygirl_black",
3
+ "./docs/resource/X2Painting/gradio_examples/02_si.jpg": "male_black",
4
+ "./docs/resource/X2Painting/gradio_examples/03_lian.jpg": "tree_black",
5
+ "./docs/resource/X2Painting/gradio_examples/04_wei.jpg": "winter_black",
6
+ "./docs/resource/X2Painting/gradio_examples/05_lai.jpg": "dunhuanggirl_yellow",
7
+ "./docs/resource/X2Painting/gradio_examples/06_cheng.jpg": "shuimocartoon_green",
8
+ "./docs/resource/X2Painting/gradio_examples/07_shi.jpg": "cartoongirl3_green",
9
+ "./docs/resource/X2Painting/gradio_examples/08_shi.jpg": "phoenix_white",
10
+ "./docs/resource/X2Painting/gradio_examples/09_yan.jpg": "cartoongirl2_while",
11
+ "./docs/resource/X2Painting/gradio_examples/10_shi.jpg": "gufenggirl_white",
12
+ "./docs/resource/X2Painting/gradio_examples/11_ren.jpg": "shuimocartoonfox_black",
13
+ "./docs/resource/X2Painting/gradio_examples/12_gong.jpg": "shuimocartoongirl2_green",
14
+ "./docs/resource/X2Painting/gradio_examples/13_zhi.jpg": "shuimowood2_black",
15
+ "./docs/resource/X2Painting/gradio_examples/14_neng.jpg": "shuimowood_black",
16
+ "./docs/resource/X2Painting/gradio_examples/15_chan.jpg": "tiankongzhicheng_black",
17
+ "./docs/resource/X2Painting/gradio_examples/16_pin.jpg": "shuimocartoongirl_black",
18
+ "./docs/resource/X2Painting/gradio_examples/17_ce.jpg": "shuimoflower_black",
19
+ "./docs/resource/X2Painting/gradio_examples/18_shi.jpg": "cartoongirl_black",
20
+ "./docs/resource/X2Painting/gradio_examples/19_ban.jpg": "shuimodesigner_black",
21
+ }
interface_modules/__init__.py ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==3.35.2
2
+ requests
3
+ Pillow==9.5.0