jaimin commited on
Commit
1011fc1
1 Parent(s): e314b9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -11,7 +11,6 @@ from utils import is_url, download_file, get_jpg_files, MODEL_DIR
11
 
12
  TMP_DIR = "./__pycache__"
13
 
14
-
15
  @dataclass
16
  class Cfg:
17
  detector_weights: str
@@ -21,7 +20,6 @@ class Cfg:
21
  disable_faces: bool = False
22
  draw: bool = True
23
 
24
-
25
  class ValidImgDetector:
26
  predictor = None
27
 
@@ -39,7 +37,7 @@ class ValidImgDetector:
39
  mode: str,
40
  predictor: Predictor,
41
  ) -> np.ndarray:
42
- # input is rgb image, output must be rgb too
43
  predictor.detector.detector_kwargs["conf"] = score_threshold
44
  predictor.detector.detector_kwargs["iou"] = iou_threshold
45
  if mode == "Use persons and faces":
@@ -79,8 +77,8 @@ def infer(photo: str):
79
  photo = download_file(photo, f"{TMP_DIR}/download.jpg")
80
 
81
  detector = ValidImgDetector()
82
- if not photo or not os.path.exists(photo) or imghdr.what(photo) == None:
83
- return None, None, None, "请正确输入图片 Please input image correctly"
84
 
85
  return detector.valid_img(photo)
86
 
@@ -88,30 +86,30 @@ def infer(photo: str):
88
  if __name__ == "__main__":
89
  with gr.Blocks() as iface:
90
  warnings.filterwarnings("ignore")
91
- with gr.Tab("上传模式 Upload Mode"):
92
  gr.Interface(
93
  fn=infer,
94
- inputs=gr.Image(label="上传照片 Upload Photo", type="filepath"),
95
  outputs=[
96
- gr.Image(label="检测结果 Detection Result", type="numpy"),
97
- gr.Textbox(label="存在儿童 Has Child"),
98
- gr.Textbox(label="存在女性 Has Female"),
99
- gr.Textbox(label="存在男性 Has Male"),
100
  ],
101
  examples=get_jpg_files(f"{MODEL_DIR}/examples"),
102
  allow_flagging="never",
103
  cache_examples=False,
104
  )
105
 
106
- with gr.Tab("在线模式 Online Mode"):
107
  gr.Interface(
108
  fn=infer,
109
- inputs=gr.Textbox(label="网络图片链接 Online Picture URL"),
110
  outputs=[
111
- gr.Image(label="检测结果 Detection Result", type="numpy"),
112
- gr.Textbox(label="存在儿童 Has Child"),
113
- gr.Textbox(label="存在女性 Has Female"),
114
- gr.Textbox(label="存在男性 Has Male"),
115
  ],
116
  allow_flagging="never",
117
  )
 
11
 
12
  TMP_DIR = "./__pycache__"
13
 
 
14
  @dataclass
15
  class Cfg:
16
  detector_weights: str
 
20
  disable_faces: bool = False
21
  draw: bool = True
22
 
 
23
  class ValidImgDetector:
24
  predictor = None
25
 
 
37
  mode: str,
38
  predictor: Predictor,
39
  ) -> np.ndarray:
40
+ # input is RGB image, output must be RGB too
41
  predictor.detector.detector_kwargs["conf"] = score_threshold
42
  predictor.detector.detector_kwargs["iou"] = iou_threshold
43
  if mode == "Use persons and faces":
 
77
  photo = download_file(photo, f"{TMP_DIR}/download.jpg")
78
 
79
  detector = ValidImgDetector()
80
+ if not photo or not os.path.exists(photo) or imghdr.what(photo) is None:
81
+ return None, None, None, "Please input the image correctly"
82
 
83
  return detector.valid_img(photo)
84
 
 
86
  if __name__ == "__main__":
87
  with gr.Blocks() as iface:
88
  warnings.filterwarnings("ignore")
89
+ with gr.Tab("Upload Mode"):
90
  gr.Interface(
91
  fn=infer,
92
+ inputs=gr.Image(label="Upload Photo", type="filepath"),
93
  outputs=[
94
+ gr.Image(label="Detection Result", type="numpy"),
95
+ gr.Textbox(label="Has Child"),
96
+ gr.Textbox(label="Has Female"),
97
+ gr.Textbox(label="Has Male"),
98
  ],
99
  examples=get_jpg_files(f"{MODEL_DIR}/examples"),
100
  allow_flagging="never",
101
  cache_examples=False,
102
  )
103
 
104
+ with gr.Tab("Online Mode"):
105
  gr.Interface(
106
  fn=infer,
107
+ inputs=gr.Textbox(label="Online Picture URL"),
108
  outputs=[
109
+ gr.Image(label="Detection Result", type="numpy"),
110
+ gr.Textbox(label="Has Child"),
111
+ gr.Textbox(label="Has Female"),
112
+ gr.Textbox(label="Has Male"),
113
  ],
114
  allow_flagging="never",
115
  )