aayanb09 commited on
Commit
0ce54aa
·
verified ·
1 Parent(s): 2564873

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+ import os
6
+
7
+ # Load model (make sure best.pt is in the same directory)
8
+ MODEL_PATH = "best.pt"
9
+
10
+ if not os.path.exists(MODEL_PATH):
11
+ raise FileNotFoundError("best.pt not found. Upload your trained model to the Space.")
12
+
13
+ model = YOLO(MODEL_PATH)
14
+
15
+ def predict(image):
16
+ """
17
+ Run YOLOv8 pose inference on uploaded image
18
+ """
19
+ results = model(image)
20
+
21
+ # Plot result with keypoints
22
+ annotated_frame = results[0].plot()
23
+
24
+ return annotated_frame
25
+
26
+ title = "🐶 DogFLW YOLOv8 Pose Detection"
27
+ description = """
28
+ Upload an image of a dog to detect facial keypoints using a trained YOLOv8 pose model.
29
+ """
30
+
31
+ demo = gr.Interface(
32
+ fn=predict,
33
+ inputs=gr.Image(type="pil"),
34
+ outputs=gr.Image(type="numpy"),
35
+ title=title,
36
+ description=description,
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ demo.launch()