import gradio as gr
import os.path
from PIL import Image
def output(image_path,img_id,rule):
print(image_path)
output_path = './output'
caption = 'person . mask'
flag = False
save_image_path = os.path.join(output_path,'test'+img_id+'.jpg')
print(save_image_path)
save_image = Image.open(save_image_path).convert("RGB")
return save_image
with gr.Blocks() as demo:
gr.Markdown("
服务监管效果Demo
")
gr.Markdown("""
Tips:
- 由于huggingface space不支持提供GPU,本Demo只支持cache中的三个样例效果展示
- 目前基于GLIP的架构仅支持口罩佩戴监管,后续可以增加和选择其他规则
- 判断部分采用的模型为ALBEF_14M.pth
""")
with gr.Row():
with gr.Column():
gr.Markdown("数据导入:
")
img_obj = gr.Image(value ='image/test.jpg',type = "filepath",label='object_img')
index = gr.Radio(["0", "1", "2"],value ='0',label='img_id')
gr.Markdown("规则选择(目前仅支持口罩佩戴规则):
")
rule = gr.Dropdown(["口罩佩戴规则", "隔位就坐规则", "核酸检测规则"],value='请选择规则...',label='规则选择')
with gr.Column():
gr.Markdown("效果展示:
")
img_output = gr.Image(type = "pil",label='output_img')
btn = gr.Button("Submit",variant="primary")
with gr.Row():
gr.Examples([['image/test.jpg','0','口罩佩戴规则'],['image/test1.jpg','1','口罩佩戴规则'],['image/test2.jpg','2','口罩佩戴规则']],[img_obj,index,rule],[img_output],output,True)
btn.click(fn=output,inputs=[img_obj,index,rule],outputs=[img_output],)
demo.launch()