test / app.py
spreaticsjcastle's picture
add face detection
94da2f2
raw
history blame
736 Bytes
import gradio as gr
# load libraries
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
from supervision import Detections
from PIL import Image
# download model
model_path = hf_hub_download(
repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt"
)
# load model
model = YOLO(model_path)
import cv2
import numpy as np
import gradio as gr
def sepia(input_img):
output = model(input_img)
results = Detections.from_ultralytics(output[0])
arr_int = results.xyxy.astype(int)
for x, y, x2, y2 in arr_int:
cv2.rectangle(input_img, (x, y), (x2, y2), (0, 255, 0), 2)
return input_img
demo = gr.Interface(sepia, gr.Image(), "image")
if __name__ == "__main__":
demo.launch()