sakshi116 commited on
Commit
4691ed8
·
verified ·
1 Parent(s): 5679950

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +51 -0
  2. yolov8n-face.pt +3 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load YOLOv8 face model (make sure it's in the same directory)
7
+ model = YOLO("yolov8n-face.pt")
8
+
9
+ # Image detection
10
+ def detect_faces(image, conf):
11
+ results = model.predict(source=image, conf=conf)
12
+ result_img = results[0].plot()
13
+ return Image.fromarray(result_img)
14
+
15
+ # Webcam detection
16
+ def detect_faces_live(frame, conf):
17
+ results = model.predict(source=frame, conf=conf)
18
+ result_frame = results[0].plot()
19
+ return Image.fromarray(result_frame)
20
+
21
+ # Gradio interface
22
+ title = "👤 Real-Time Face Detection with YOLOv8"
23
+ description = """
24
+ Upload an image or use your webcam to detect faces in real-time.
25
+ Powered by **Ultralytics YOLOv8** and **Gradio**.
26
+ """
27
+
28
+ with gr.Blocks(title=title) as app:
29
+ gr.Markdown(f"# {title}")
30
+ gr.Markdown(description)
31
+
32
+ conf_slider = gr.Slider(0.1, 1.0, value=0.5, label="Confidence Threshold")
33
+
34
+ with gr.Tab("📸 Image Upload"):
35
+ gr.Interface(
36
+ fn=detect_faces,
37
+ inputs=[gr.Image(type="pil", label="Upload Image"), conf_slider],
38
+ outputs=gr.Image(label="Detected Faces"),
39
+ live=False
40
+ )
41
+
42
+ with gr.Tab("🎥 Live Webcam"):
43
+ gr.Interface(
44
+ fn=detect_faces_live,
45
+ inputs=[gr.Image(type="numpy", streaming=True), conf_slider],
46
+ outputs=gr.Image(label="Detected Faces"),
47
+ live=True
48
+ )
49
+
50
+ if __name__ == "__main__":
51
+ app.launch()
yolov8n-face.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d17b38523a994b13ee604b67f02791ca0f43b9f446a32fd7bc44e17c56ead077
3
+ size 6250099