Spaces:
Sleeping
Sleeping
ZhangTianqi
commited on
Commit
•
fcd066f
1
Parent(s):
ea6c55a
- app.py +28 -10
- image/test1.jpg +0 -0
- image/test2.jpg +0 -0
- output/test.jpg +0 -0
- output/test0.jpg +0 -0
- output/test1.jpg +0 -0
- output/test2.jpg +0 -0
app.py
CHANGED
@@ -2,21 +2,39 @@ import gradio as gr
|
|
2 |
import os.path
|
3 |
from PIL import Image
|
4 |
|
5 |
-
def output(image_path):
|
6 |
-
|
|
|
7 |
caption = 'person . mask'
|
8 |
flag = False
|
9 |
-
save_image_path = os.path.join(output_path,
|
|
|
10 |
save_image = Image.open(save_image_path).convert("RGB")
|
11 |
return save_image
|
12 |
|
13 |
with gr.Blocks() as demo:
|
14 |
-
gr.Markdown("<h1><center
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
demo.launch()
|
|
|
2 |
import os.path
|
3 |
from PIL import Image
|
4 |
|
5 |
+
def output(image_path,img_id,rule):
|
6 |
+
print(image_path)
|
7 |
+
output_path = './output'
|
8 |
caption = 'person . mask'
|
9 |
flag = False
|
10 |
+
save_image_path = os.path.join(output_path,'test'+img_id+'.jpg')
|
11 |
+
print(save_image_path)
|
12 |
save_image = Image.open(save_image_path).convert("RGB")
|
13 |
return save_image
|
14 |
|
15 |
with gr.Blocks() as demo:
|
16 |
+
gr.Markdown("<h1><center>服务监管效果Demo</center></h1>")
|
17 |
+
gr.Markdown("""
|
18 |
+
Tips:
|
19 |
+
- 由于huggingface space不支持提供GPU,本Demo只支持cache中的三个样例效果展示
|
20 |
+
- 目前基于GLIP的架构仅支持口罩佩戴监管,后续可以增加和选择其他规则
|
21 |
+
- 判断部分采用的模型为ALBEF_14M.pth
|
22 |
+
""")
|
23 |
+
with gr.Row():
|
24 |
+
with gr.Column():
|
25 |
+
gr.Markdown("<h2>数据导入:</h2>")
|
26 |
+
img_obj = gr.Image(value ='image/test.jpg',type = "filepath",label='object_img')
|
27 |
+
index = gr.Radio(["0", "1", "2"],value ='0',label='img_id')
|
28 |
+
gr.Markdown("<h2>规则选择(目前仅支持口罩佩戴规则):</h2>")
|
29 |
+
rule = gr.Dropdown(["口罩佩戴规则", "隔位就坐规则", "核酸检测规则"],value='请选择规则...',label='规则选择')
|
30 |
+
with gr.Column():
|
31 |
+
gr.Markdown("<h2>效果展示:</h2>")
|
32 |
+
img_output = gr.Image(type = "pil",label='output_img')
|
33 |
+
btn = gr.Button("Submit",variant="primary")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
gr.Examples([['image/test.jpg','0','口罩佩戴规则'],['image/test1.jpg','1','口罩佩戴规则'],['image/test2.jpg','2','口罩佩戴规则']],[img_obj,index,rule],[img_output],output,True)
|
37 |
+
|
38 |
+
btn.click(fn=output,inputs=[img_obj,index,rule],outputs=[img_output],)
|
39 |
|
40 |
demo.launch()
|
image/test1.jpg
ADDED
image/test2.jpg
ADDED
output/test.jpg
DELETED
Binary file (74.4 kB)
|
|
output/test0.jpg
ADDED
output/test1.jpg
ADDED
output/test2.jpg
ADDED