Irina Tolstykh commited on
Commit
21ce843
1 Parent(s): a76360d

Add application file

Browse files
Files changed (3) hide show
  1. app.py +52 -0
  2. images/jennifer_lawrence.jpg +0 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import pathlib
4
+ import os
5
+ import cv2
6
+ import gradio as gr
7
+ import huggingface_hub
8
+ import numpy as np
9
+ import functools
10
+
11
+ from ultralytics import YOLO
12
+ from ultralytics.yolo.engine.results import Results
13
+
14
+ TITLE = 'Age and Gender Estimation with Transformers from Face and Body Images in the Wild'
15
+ DESCRIPTION = 'This is an official demo for https://github.com/...'
16
+
17
+ HF_TOKEN = os.getenv('HF_TOKEN')
18
+
19
+ def load_model():
20
+ path = huggingface_hub.hf_hub_download('iitolstykh/demo_yolov8_detector',
21
+ 'yolov8x_person_face.pt',
22
+ use_auth_token=HF_TOKEN)
23
+ yolo = YOLO(path)
24
+ yolo.fuse()
25
+
26
+ return yolo
27
+
28
+ def detect(image: np.ndarray, detector: YOLO) -> np.ndarray:
29
+ detector_kwargs = {'conf': 0.5, 'iou': 0.5, 'half': False, 'verbose': False}
30
+
31
+ results: Results = detector.predict(image, **detector_kwargs)[0]
32
+ out_im = results.plot()
33
+
34
+ return out_im
35
+
36
+
37
+ detector = load_model()
38
+
39
+ image_dir = pathlib.Path('images')
40
+ examples = [[path.as_posix()] for path in sorted(image_dir.glob('*.jpg'))]
41
+
42
+ func = functools.partial(detect, detector=detector)
43
+
44
+ gr.Interface(
45
+ fn=func,
46
+ inputs=gr.Image(label='Input', type='numpy'),
47
+ outputs=gr.Image(label='Output', type='numpy'),
48
+ examples=examples,
49
+ examples_per_page=30,
50
+ title=TITLE,
51
+ description=DESCRIPTION,
52
+ ).launch(show_api=False)
images/jennifer_lawrence.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Cython==0.29.28
2
+ ultralytics
3
+ timm==0.8.13.dev0
4
+ huggingface_hub
5
+ gradio