drizzlezyk commited on
Commit
7a6c4ed
1 Parent(s): c24b48b

add app, util, html, background

Browse files
Files changed (4) hide show
  1. app.py +103 -0
  2. background.jpg +0 -0
  3. header.html +27 -0
  4. utils.py +49 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import gradio as gr
4
+ from PIL import Image
5
+ from io import BytesIO
6
+
7
+ from utils import get_token
8
+
9
+
10
+ def generate_figure(style, desc):
11
+ url = "https://a2f051d4cabf45f885d7b0108edc9b9c.infer.ovaijisuan.com/" \
12
+ "v1/infers/975eedfd-6e15-4571-8ca9-b945da0da24b/wukong_hf"
13
+
14
+ requests_json = {
15
+ "user_name": "huggingface",
16
+ "style": style,
17
+ "desc": desc
18
+ }
19
+
20
+ headers = {
21
+ "Content-Type": "application/json",
22
+ "X-Auth-Token": token
23
+ }
24
+
25
+ response = requests.post(url, json=requests_json, headers=headers, verify=False)
26
+ response = json.loads(response.text)
27
+ status = response["status"]
28
+ assert status == 200
29
+ url_list = response["output_image_url"]
30
+
31
+ image1 = Image.open(BytesIO(requests.get(url_list[0]).content))
32
+ image2 = Image.open(BytesIO(requests.get(url_list[1]).content))
33
+ image3 = Image.open(BytesIO(requests.get(url_list[2]).content))
34
+ image4 = Image.open(BytesIO(requests.get(url_list[3]).content))
35
+
36
+ return image1, image2, image3, image4
37
+
38
+
39
+ def read_content(file_path: str) -> str:
40
+ with open(file_path, 'r', encoding='utf-8') as f:
41
+ content = f.read()
42
+
43
+ return content
44
+
45
+
46
+ token = get_token()
47
+
48
+
49
+ examples = [
50
+ ["宫崎骏", "城市夜景"],
51
+ ["新海诚", "海滩 美景"],
52
+ ["赛博朋克", "一只猫"],
53
+
54
+ ]
55
+
56
+ css = """
57
+ .gradio-container {background-image: url('file=./background.jpg'); background-size:cover; background-repeat: no-repeat;}
58
+
59
+ #generate {
60
+ background: linear-gradient(#D8C5EB, #C5E8EB,#90CCF6);
61
+ border: 1px solid #C5E8EB;
62
+ border-radius: 8px;
63
+ color: #407BEA
64
+ }
65
+
66
+ """
67
+
68
+ with gr.Blocks(css=css) as demo:
69
+ gr.HTML(read_content("./header.html"))
70
+
71
+ gr.Markdown("# MindSpore Wukong•Huahua "
72
+ " \n With the help of Wukong dataset, the largest Chinese open-source multi-modal dataset for training,"
73
+ " the Wukong-Huahua model has excellent Chinese text-image generation capabilities."
74
+ " Wukong-Huahua can identify various scene descriptions and painting styles,"
75
+ " bringing users a good experience.")
76
+
77
+ with gr.Tab("Figure Generation"):
78
+ style_input = gr.Textbox(lines=1,
79
+ placeholder="Input the style of figure you want to generate.",
80
+ label="例如:新海诚 宫崎骏 梵高 莫奈 赛博朋克",
81
+ elem_id="style-input")
82
+ desc_input = gr.Textbox(lines=1,
83
+ placeholder="Input a sentence to describe the figure you want to generate.",
84
+ label="")
85
+ gr.Examples(
86
+ examples=examples,
87
+ inputs=[style_input, desc_input],
88
+ )
89
+ generate_button = gr.Button("Generate", elem_id="generate")
90
+ with gr.Row():
91
+ img_output1 = gr.Image(type="pil")
92
+ img_output2 = gr.Image(type="pil")
93
+ img_output3 = gr.Image(type="pil")
94
+ img_output4 = gr.Image(type="pil")
95
+
96
+ with gr.Accordion("Open for More!"):
97
+ gr.Markdown("- [The Foundation models Platform for Mindspore](https://xihe.mindspore.cn/)")
98
+
99
+ generate_button.click(generate_figure,
100
+ inputs=[style_input, desc_input],
101
+ outputs=[img_output1, img_output2, img_output3, img_output4])
102
+
103
+ demo.launch()
background.jpg ADDED
header.html ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
2
+ <div
3
+ style="
4
+ display: inline-flex;
5
+ gap: 0.8rem;
6
+ font-size: 1.75rem;
7
+ margin-bottom: 10px;
8
+ margin-left: 220px;
9
+ justify-content: center;
10
+ "
11
+ >
12
+ </div>
13
+ <div
14
+ style="
15
+ display: inline-flex;
16
+ align-items: center;
17
+ gap: 0.8rem;
18
+ font-size: 1.75rem;
19
+ margin-bottom: 10px;
20
+ justify-content: center;
21
+ ">
22
+ <a href="https://github.com/mindspore-ai/mindspore"><h1 style="font-weight: 900; align-items: center; margin-bottom: 7px;">
23
+ </h1></a>
24
+ </div>
25
+ <a href="https://github.com/mindspore-ai/mindspore"><img src="https://obs-xihe-beijing4-test.obs.cn-north-4.myhuaweicloud.com/xihe-img/huggingface/mindspore.png" width="100%"></a>
26
+
27
+ </div>
utils.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+
4
+
5
+ def get_token():
6
+ username = os.environ["username"]
7
+ domain_name = os.environ["domain_name"]
8
+ domain_pwd = os.environ["domain_pwd"]
9
+
10
+ url = "https://iam.cn-central-221.myhuaweicloud.com/v3/auth/tokens"
11
+
12
+ requests_json = {
13
+ "auth": {
14
+ "identity": {
15
+ "methods": ["password"],
16
+ "password": {
17
+ "user": {
18
+ "name": username,
19
+ "password": domain_pwd,
20
+ "domain": {
21
+ "name": domain_name
22
+ }
23
+ }
24
+ }
25
+ },
26
+ "scope": {
27
+ "project": {
28
+ "name": "cn-central-221"
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ headers = {
35
+ "Content-Type": "text/plain"
36
+ }
37
+
38
+ response = requests.post(url, json=requests_json, headers=headers)
39
+
40
+ assert response.status_code == 201
41
+
42
+ result = response.headers
43
+ print("token success")
44
+
45
+ return result['X-Subject-Token']
46
+
47
+
48
+ if __name__ == "__main__":
49
+ get_token()