aayanb09 commited on
Commit
4794ece
·
verified ·
1 Parent(s): 90d6763

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -24
app.py CHANGED
@@ -1,40 +1,26 @@
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()
 
1
  import gradio as gr
2
  from ultralytics import YOLO
 
 
3
  import os
4
 
 
5
  MODEL_PATH = "best.pt"
6
 
7
  if not os.path.exists(MODEL_PATH):
8
+ raise FileNotFoundError("best.pt not found.")
9
 
10
  model = YOLO(MODEL_PATH)
11
 
12
  def predict(image):
 
 
 
13
  results = model(image)
14
+ return results[0].plot()
15
 
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("# 🐶 DogFLW Pose Detection")
18
+ gr.Markdown("Upload an image to detect dog facial landmarks.")
19
 
20
+ input_img = gr.Image(type="pil")
21
+ output_img = gr.Image()
22
 
23
+ btn = gr.Button("Run Detection")
24
+ btn.click(predict, inputs=input_img, outputs=output_img)
 
 
25
 
26
+ demo.launch()