File size: 3,556 Bytes
117b368 |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import gradio as gr
from eval_fashion_person import *
from name_entity_recognition import *
from utils.operate_json import *
def eval_image(input_image, progress=gr.Progress()):
if input_image is None:
raise gr.Error("未上传图片,请先上传图片")
progress((0, 3), desc="上传图片中")
img_name = get_one_name()
input_image = output_to_binary(input_image)
save_tx(file_data=input_image,
file_name=img_name)
progress((1, 3), desc="评估分数中")
data = eval_fashion_person_tx_url(img_name)
progress((2, 3), desc="识别类型中")
reason = data['fashion_eval_reason']
score = data['fashion_score_predict']
score = ("未识别出" if score == -1 else score)
data = {}
while not data:
text = name_entity_recognition(reason)
data = text_to_json(text)
keys_to_check = [
'type',
'upper_garment',
'lower_garment',
'headgear',
'sock',
'shoe',
'accessory',
'backpack',
'action',
'countenance'
]
data = {k: ("未识别出" if data.get(k) is None else data[k]) for k in keys_to_check}
data = {k: ("未识别出" if v == "None" else v) for k, v in data.items()}
result = [reason,
score,
data['type'],
data['upper_garment'],
data['lower_garment'],
data['headgear'],
data['sock'],
data['shoe'],
data['accessory'],
data['backpack'],
data['action'],
data['countenance']]
return result
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
Image_input = gr.Image(label="请上传图片",
height=640,
width=640,
show_share_button=False)
with gr.Row():
run_button = gr.Button(value="开始评估")
score = gr.Textbox(label="评分")
with gr.Column():
with gr.Group():
with gr.Row():
with gr.Column():
type = gr.Textbox(label="人物类型")
headgear = gr.Textbox(label="帽子类型")
shoe = gr.Textbox(label="鞋子类型")
backpack = gr.Textbox(label="背包类型")
countenance = gr.Textbox(label="表情类型")
with gr.Column():
upper_garment = gr.Textbox(label="上衣类型")
lower_garment = gr.Textbox(label="下衣类型")
sock = gr.Textbox(label="袜子类型")
accessory = gr.Textbox(label="配饰类型")
action = gr.Textbox(label="动作类型")
text_output = gr.Textbox(label="时尚买手小玲评估结果")
run_button.click(eval_image,
inputs=Image_input,
outputs=[text_output,
score,
type,
upper_garment,
lower_garment,
headgear,
sock,
shoe,
accessory,
backpack,
action,
countenance])
demo.queue().launch()
|