Spaces:
Build error
Build error
File size: 1,713 Bytes
d5fe608 fcad0c6 d5fe608 a801b25 c8aa0bd a801b25 c8aa0bd a801b25 c8aa0bd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import os
os.system('pip install insightface==0.6.2')
import gradio as gr
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from insightface.data import get_image as ins_get_image
from PIL import Image
import PIL
app = FaceAnalysis(name="buffalo_sc", providers=['CPUExecutionProvider'], allowed_modules=['detection'])
article="<p style='text-align: center'><a href='' target='_blank'>Face Detection</a></p>"
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."
def show_preds(input_image, detection_threshold=0.2):
if detection_threshold<0.05 or detection_threshold==None: detection_threshold = 0.10
app.prepare(ctx_id=0, det_size=(640, 640), det_thresh=detection_threshold)
img = PIL.Image.fromarray(input_image, 'RGB')
basewidth = 900
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
#display(img)
faces = app.get(np.array(img))
detected = app.draw_on(np.array(img), faces)
return detected
detection_threshold_slider = gr.inputs.Slider(minimum=0, maximum=1, step=0.05, default=0.2, label="Detection Threshold")
outputs = gr.outputs.Image(type="pil")
examples = [['example1.jpg',0.2], ['example2.jpg',0.2]]
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)
gr_interface.launch(inline=False, share=False, debug=True) |