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="
" 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=True, debug=True)