aayanb09 commited on
Commit
48787b8
·
verified ·
1 Parent(s): 8b4cbfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -1,26 +1,29 @@
 
 
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("Upload best.pt to the Space root directory.")
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 a dog image to detect facial keypoints.")
19
-
20
- input_img = gr.Image(type="pil")
21
- output_img = gr.Image()
22
-
23
- run_button = gr.Button("Run Detection")
24
- run_button.click(predict, inputs=input_img, outputs=output_img)
25
-
26
- demo.launch()
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import numpy as np
3
  import gradio as gr
4
  from ultralytics import YOLO
 
5
 
6
  MODEL_PATH = "best.pt"
 
 
 
 
7
  model = YOLO(MODEL_PATH)
8
 
9
+ def predict(image, conf):
10
+ if image is None:
11
+ return None
12
+ results = model.predict(source=np.array(image), conf=conf, imgsz=640, verbose=False)[0]
13
+ plotted = results.plot() # BGR numpy array
14
+ plotted = plotted[:, :, ::-1] # BGR -> RGB
15
+ return Image.fromarray(plotted)
16
+
17
+ demo = gr.Interface(
18
+ fn=predict,
19
+ inputs=[
20
+ gr.Image(type="pil", label="Input Image"),
21
+ gr.Slider(0.05, 0.9, value=0.25, step=0.05, label="Confidence"),
22
+ ],
23
+ outputs=gr.Image(type="pil", label="Pose Result"),
24
+ title="DogFLW YOLOv8 Pose",
25
+ description="Upload a dog image to detect 46 facial landmarks."
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()