[tlthr764]
commited on
Commit
·
411d541
1
Parent(s):
555b3f0
image_track commit
Browse files
app.py
CHANGED
@@ -1,7 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from ultralytics import YOLO
|
4 |
+
from supervision import Detections
|
5 |
+
from PIL import Image
|
6 |
+
import torch
|
7 |
+
import numpy as np
|
8 |
import gradio as gr
|
9 |
|
10 |
+
def detect_faces(input_img):
|
11 |
+
# download model
|
12 |
+
model_path = hf_hub_download(
|
13 |
+
repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt"
|
14 |
+
)
|
15 |
|
16 |
+
# load model
|
17 |
+
model = YOLO(model_path)
|
18 |
+
|
19 |
+
# 이미지를 YOLO 모델 입력 형식으로 변환
|
20 |
+
image_cv = cv2.cvtColor(np.array(input_img), cv2.COLOR_RGB2BGR)
|
21 |
+
|
22 |
+
# 얼굴 탐지
|
23 |
+
output = model(input_img)
|
24 |
+
results = Detections.from_ultralytics(output[0])
|
25 |
+
|
26 |
+
# 탐지 결과 그리기
|
27 |
+
drawn_image = draw_rect_with_conf(image_cv, results)
|
28 |
+
|
29 |
+
# OpenCV 이미지를 PIL 이미지로 변환
|
30 |
+
drawn_image_pil = Image.fromarray(cv2.cvtColor(drawn_image, cv2.COLOR_BGR2RGB))
|
31 |
+
return drawn_image_pil
|
32 |
+
|
33 |
+
def gradio_interface(input_img):
|
34 |
+
# 얼굴 탐지 함수 호출
|
35 |
+
detected_img = detect_faces(input_img)
|
36 |
+
return detected_img
|
37 |
+
|
38 |
+
# Gradio 인터페이스 설정
|
39 |
+
demo = gr.Interface(fn=gradio_interface, inputs=gr.Image(type="pil"), outputs="image")
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
demo.launch()
|