Spaces:
Build error
Build error
Commit
·
c8aa0bd
1
Parent(s):
a801b25
Added face detection codes
Browse files- app.py +35 -4
- example1.jpg +0 -0
- example2.jpg +0 -0
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -1,7 +1,38 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import insightface
|
| 4 |
+
from insightface.app import FaceAnalysis
|
| 5 |
+
from insightface.data import get_image as ins_get_image
|
| 6 |
+
from PIL import Image
|
| 7 |
|
| 8 |
+
import PIL
|
|
|
|
| 9 |
|
| 10 |
+
app = FaceAnalysis(name="buffalo_sc", providers=['CPUExecutionProvider'], allowed_modules=['detection'])
|
| 11 |
+
|
| 12 |
+
article="<p style='text-align: center'><a href='' target='_blank'>Face Detection</a></p>"
|
| 13 |
+
description = "This Face Detection Project uses InsightFace Library (https://insightface.ai/). We use RetinaFace-500MF model for the Face Detection. Upload an image or click an example image to use."
|
| 14 |
+
|
| 15 |
+
def show_preds(input_image, detection_threshold=0.2):
|
| 16 |
+
|
| 17 |
+
if detection_threshold<0.05 or detection_threshold==None: detection_threshold = 0.10
|
| 18 |
+
|
| 19 |
+
app.prepare(ctx_id=0, det_size=(640, 640), det_thresh=detection_threshold)
|
| 20 |
+
|
| 21 |
+
img = PIL.Image.fromarray(input_image, 'RGB')
|
| 22 |
+
basewidth = 900
|
| 23 |
+
wpercent = (basewidth/float(img.size[0]))
|
| 24 |
+
hsize = int((float(img.size[1])*float(wpercent)))
|
| 25 |
+
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
|
| 26 |
+
|
| 27 |
+
#display(img)
|
| 28 |
+
faces = app.get(np.array(img))
|
| 29 |
+
detected = app.draw_on(np.array(img), faces)
|
| 30 |
+
return detected
|
| 31 |
+
|
| 32 |
+
detection_threshold_slider = gr.inputs.Slider(minimum=0, maximum=1, step=0.05, default=0.2, label="Detection Threshold")
|
| 33 |
+
outputs = gr.outputs.Image(type="pil")
|
| 34 |
+
|
| 35 |
+
examples = [['example1.jpg',0.2], ['example2.jpg',0.2]]
|
| 36 |
+
|
| 37 |
+
gr_interface = gr.Interface(fn=show_preds, inputs=["image", detection_threshold_slider], outputs=outputs, title='Face Detection App', article=article,description=description, examples=examples, analytics_enabled = True, enable_queue=True)
|
| 38 |
+
gr_interface.launch(inline=False, share=False, debug=True)
|
example1.jpg
ADDED
|
example2.jpg
ADDED
|
requirements.txt
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
insightface==0.5
|
| 2 |
+
onnx==1.10.2
|
| 3 |
+
onnxruntime==1.10.0
|