''' Author: [egrt] Date: 2022-08-05 15:30:04 LastEditors: [egrt] LastEditTime: 2022-08-17 20:58:37 Description: ''' import os os.system('pip install requirements.txt') import gradio as gr from AutoML import Classification classfication = Classification() with gr.Blocks() as demo: with gr.Row(): with gr.Column(): name_box = gr.Textbox(label="艺术家姓名") date_box = gr.Number(label="艺术品创作时间(年)") classification_box = gr.CheckboxGroup(label="艺术品类型", choices=["中国山水画", "中国花鸟画", "风景油画", "水粉画", "油画", "布面油画", "没骨画", "中国画"]) level_box = gr.CheckboxGroup(label="艺术家级别", choices=["国家级"]) height_box = gr.Number(label="艺术品高度(cm)") width_box = gr.Number(label="艺术品宽度(cm)") with gr.Column(): title_box = gr.Markdown("## 艺术品价值预测Demo") image_box = gr.Image(label="艺术品照片", type='pil') with gr.Row(): submit_btn = gr.Button("开始预测") error_box = gr.Textbox(label="错误", visible=False) with gr.Row(visible=False) as output_col: prices_box = gr.Number(label="预测的艺术品价格(¥)") def submit(name, date, classification, level, height, width, image): # 填写信息错误则显示报错提示框 if len(name)==0 or len(classification)==0 or len(level) == 0 or image==None: return {error_box: gr.update(value="请填写所有信息", visible=True)} else: # 正确预测之后则去除报错提示框 error_box: gr.update(visible=False) prices = classfication.detect_one(name, date, level[0], classification[0], height, width) return { output_col: gr.update(visible=True), prices_box: int(prices), } submit_btn.click( submit, [name_box, date_box, classification_box, level_box, height_box, width_box, image_box], [error_box, prices_box, output_col], ) demo.launch()