'add'
Browse files- gradio_practice.py +27 -0
gradio_practice.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# load libraries
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from supervision import Detections
|
| 5 |
+
import cv2
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# download model
|
| 10 |
+
model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
|
| 11 |
+
|
| 12 |
+
# load model
|
| 13 |
+
model = YOLO(model_path)
|
| 14 |
+
|
| 15 |
+
def bounding(input_img):
|
| 16 |
+
output = model(input_img)
|
| 17 |
+
results = Detections.from_ultralytics(output[0])
|
| 18 |
+
arr_int = results.xyxy.astype(int)
|
| 19 |
+
|
| 20 |
+
for x,y,x2,y2 in arr_int:
|
| 21 |
+
cv2.rectangle(input_img, (x,y),(x2,y2),(0,255,0),2)
|
| 22 |
+
return input_img
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(bounding, gr.Image(), "image")
|
| 27 |
+
demo.launch()
|