Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|