Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,6 @@ from supervision import Detections
|
|
5 |
from PIL import Image
|
6 |
import numpy as np
|
7 |
import cv2
|
8 |
-
import base64
|
9 |
-
import io
|
10 |
|
11 |
# Download and load the model
|
12 |
model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
|
@@ -31,12 +29,7 @@ def detect_faces(image):
|
|
31 |
# Convert back to PIL image
|
32 |
result_image = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB))
|
33 |
|
34 |
-
|
35 |
-
buffered = io.BytesIO()
|
36 |
-
result_image.save(buffered, format="PNG")
|
37 |
-
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
38 |
-
|
39 |
-
return result_image, num_faces, img_str
|
40 |
|
41 |
# Gradio Interface
|
42 |
demo = gr.Interface(
|
@@ -44,8 +37,7 @@ demo = gr.Interface(
|
|
44 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
45 |
outputs=[
|
46 |
gr.Image(type="pil", label="Detected Faces"),
|
47 |
-
gr.Number(label="Face Count")
|
48 |
-
gr.Textbox(label="Base64 Encoded Image")
|
49 |
],
|
50 |
title="Face Detection with YOLOv8",
|
51 |
description="Drag and drop an image or click to upload. The model will detect faces using YOLOv8.",
|
|
|
5 |
from PIL import Image
|
6 |
import numpy as np
|
7 |
import cv2
|
|
|
|
|
8 |
|
9 |
# Download and load the model
|
10 |
model_path = hf_hub_download(repo_id="arnabdhar/YOLOv8-Face-Detection", filename="model.pt")
|
|
|
29 |
# Convert back to PIL image
|
30 |
result_image = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB))
|
31 |
|
32 |
+
return result_image, num_faces
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Gradio Interface
|
35 |
demo = gr.Interface(
|
|
|
37 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
38 |
outputs=[
|
39 |
gr.Image(type="pil", label="Detected Faces"),
|
40 |
+
gr.Number(label="Face Count")
|
|
|
41 |
],
|
42 |
title="Face Detection with YOLOv8",
|
43 |
description="Drag and drop an image or click to upload. The model will detect faces using YOLOv8.",
|