helloway commited on
Commit
da9f688
1 Parent(s): f03dc25

Update app.py

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