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