helloway commited on
Commit
ef16984
·
1 Parent(s): 64e8911

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import numpy as np
4
+ from PIL import Image
5
+ import gradio as gr
6
+
7
+
8
+ def gen_image(desc: str):
9
+ """generate the image from the wukong huahua model of ascend server in Wuhan AICC
10
+ Args:
11
+ desc(str): the input description text
12
+ """
13
+ if not desc:
14
+ return
15
+ access_token = os.environ['token']
16
+ headers = {'content-type': "application/json", 'X-Subject-Token': access_token}
17
+
18
+ url = f"https://a2f051d4cabf45f885d7b0108edc9b9c.infer.ovaijisuan.com/v1/infers/dce9ad51-7cde-4eeb-8291-ae29f267ed2c/wukong-hf"
19
+ body = {
20
+ "desc": desc,
21
+ "style": ""
22
+ }
23
+
24
+ resp_data = requests.post(url, json=body, headers=headers)
25
+ if resp_data['status'] != 200:
26
+ return []
27
+ img_np = resp_data['output_image_list'][0]
28
+ image = Image.fromarray(np.uint8(img_np))
29
+ return [image]
30
+
31
+
32
+ examples = [
33
+ '天空之城 赛博朋克 动漫',
34
+ '秋水共长天一色',
35
+ '海滩 蓝天 美景',
36
+ '教堂 巴洛克风格',
37
+ '落日 莫奈',
38
+ '来自深渊 雪山飞狐'
39
+ ]
40
+
41
+ block = gr.Blocks()
42
+
43
+
44
+ with block:
45
+ with gr.Group():
46
+ with gr.Box():
47
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
48
+ text = gr.Textbox(
49
+ label="Desc",
50
+ show_label=False,
51
+ max_lines=1,
52
+ placeholder="输入中文,生成图片",
53
+ ).style(
54
+ border=(True, False, True, True),
55
+ rounded=(True, False, False, True),
56
+ container=False,
57
+ )
58
+
59
+ btn = gr.Button("Generate image").style(
60
+ margin=False,
61
+ rounded=(False, True, True, False),
62
+ )
63
+
64
+ gallery = gr.Gallery(
65
+ label="Generated images", show_label=False, elem_id="gallery"
66
+ ).style(grid=[1, 1], height="auto")
67
+
68
+ gr.Examples(examples=examples, fn=gen_image, inputs=text, outputs=gallery)
69
+
70
+ block.queue(concurrency_count=3).launch(debug=True)