yahyaahmed commited on
Commit
a5d4f49
·
verified ·
1 Parent(s): 1db04fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -5,6 +5,8 @@ from supervision import Detections
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,7 +31,12 @@ def detect_faces(image):
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,11 +44,12 @@ 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.",
44
  live=False
45
  )
46
 
47
- demo.launch()
 
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
  # Convert back to PIL image
32
  result_image = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB))
33
 
34
+ # Convert to base64 for API use
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
  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.",
52
  live=False
53
  )
54
 
55
+ demo.launch()