Irina Tolstykh commited on
Commit
8a19b0b
1 Parent(s): 1b018f5

update demo layout

Browse files
Files changed (2) hide show
  1. app.py +42 -23
  2. style.css +3 -0
app.py CHANGED
@@ -31,25 +31,30 @@ class Cfg:
31
  draw: bool = True
32
 
33
 
34
- TITLE = 'Age and Gender Estimation with Transformers from Face and Body Images in the Wild'
35
- DESCRIPTION = 'This is an official demo for https://github.com/...'
 
 
 
36
 
37
  HF_TOKEN = os.getenv('HF_TOKEN')
38
 
 
39
  def load_models():
40
  detector_path = huggingface_hub.hf_hub_download('iitolstykh/demo_yolov8_detector',
41
- 'yolov8x_person_face.pt',
42
- use_auth_token=HF_TOKEN)
43
 
44
  age_gender_path = huggingface_hub.hf_hub_download('iitolstykh/demo_xnet_volo_cross',
45
- 'checkpoint-377.pth.tar',
46
- use_auth_token=HF_TOKEN)
47
 
48
  predictor_cfg = Cfg(detector_path, age_gender_path)
49
  predictor = Predictor(predictor_cfg)
50
 
51
  return predictor
52
 
 
53
  def detect(
54
  image: np.ndarray,
55
  score_threshold: float,
@@ -79,6 +84,8 @@ def detect(
79
  detected_objects, out_im = predictor.recognize(image)
80
  return out_im[:, :, ::-1] # BGR -> RGB
81
 
 
 
82
 
83
  predictor = load_models()
84
 
@@ -87,20 +94,32 @@ examples = [[path.as_posix(), 0.4, 0.7, "Use persons and faces"] for path in sor
87
 
88
  func = functools.partial(detect, predictor=predictor)
89
 
90
- gr.Interface(
91
- fn=func,
92
- inputs=[
93
- gr.Image(label='Input', type='numpy'),
94
- gr.Slider(0, 1, value=0.4, step=0.05, label='Detector Score Threshold'),
95
- gr.Slider(0, 1, value=0.7, step=0.05, label='NMS Iou Threshold'),
96
- gr.Radio(["Use persons and faces", "Use persons only", "Use faces only"],
97
- value="Use persons and faces",
98
- label="Inference mode",
99
- info="What to use for gender and age recognition"),
100
- ],
101
- outputs=gr.Image(label='Output', type='numpy'),
102
- examples=examples,
103
- examples_per_page=30,
104
- title=TITLE,
105
- description=DESCRIPTION,
106
- ).launch(show_api=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  draw: bool = True
32
 
33
 
34
+ DESCRIPTION = """
35
+ # Age and Gender Estimation with Transformers from Face and Body Images in the Wild
36
+
37
+ This is an official demo for https://github.com/...
38
+ """
39
 
40
  HF_TOKEN = os.getenv('HF_TOKEN')
41
 
42
+
43
  def load_models():
44
  detector_path = huggingface_hub.hf_hub_download('iitolstykh/demo_yolov8_detector',
45
+ 'yolov8x_person_face.pt',
46
+ use_auth_token=HF_TOKEN)
47
 
48
  age_gender_path = huggingface_hub.hf_hub_download('iitolstykh/demo_xnet_volo_cross',
49
+ 'checkpoint-377.pth.tar',
50
+ use_auth_token=HF_TOKEN)
51
 
52
  predictor_cfg = Cfg(detector_path, age_gender_path)
53
  predictor = Predictor(predictor_cfg)
54
 
55
  return predictor
56
 
57
+
58
  def detect(
59
  image: np.ndarray,
60
  score_threshold: float,
 
84
  detected_objects, out_im = predictor.recognize(image)
85
  return out_im[:, :, ::-1] # BGR -> RGB
86
 
87
+ def clear():
88
+ return None, 0.4, 0.7, "Use persons and faces", None
89
 
90
  predictor = load_models()
91
 
 
94
 
95
  func = functools.partial(detect, predictor=predictor)
96
 
97
+ with gr.Blocks(css='style.css') as demo:
98
+ gr.Markdown(DESCRIPTION)
99
+ with gr.Row():
100
+ with gr.Column():
101
+ image = gr.Image(label='Input', type='numpy')
102
+ score_threshold = gr.Slider(0, 1, value=0.4, step=0.05, label='Detector Score Threshold')
103
+ iou_threshold = gr.Slider(0, 1, value=0.7, step=0.05, label='NMS Iou Threshold')
104
+ mode = gr.Radio(["Use persons and faces", "Use persons only", "Use faces only"],
105
+ value="Use persons and faces",
106
+ label="Inference mode",
107
+ info="What to use for gender and age recognition")
108
+
109
+ with gr.Row():
110
+ clear_button = gr.Button("Clear")
111
+ with gr.Column():
112
+ run_button = gr.Button("Submit")
113
+ with gr.Column():
114
+ result = gr.Image(label='Output', type='numpy')
115
+
116
+ inputs = [image, score_threshold, iou_threshold, mode]
117
+ gr.Examples(examples=examples,
118
+ inputs=inputs,
119
+ outputs=result,
120
+ fn=func,
121
+ cache_examples=False)
122
+ run_button.click(fn=func, inputs=inputs, outputs=result, api_name='predict')
123
+ clear_button.click(fn=clear, inputs=None, outputs=[image, score_threshold, iou_threshold, mode, result])
124
+
125
+ demo.queue(max_size=15).launch()
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ }