|
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() |
|
|