File size: 1,074 Bytes
ae07fb0
 
b5a155b
6d18b9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

from ultralytics import YOLO
import gradio as gr
import numpy as np
from PIL import Image

# -------------------------
# Load detection model
# -------------------------
model = YOLO("buck_vs_doe_Detection_best.pt")

# -------------------------
# Inference function
# -------------------------
def predict(image):
    # Run inference (YOLO accepts numpy RGB directly)
    results = model(image)

    # Take first result (single image)
    r = results[0]

    # Plot results (BGR numpy array)
    im_bgr = r.plot()

    # Convert BGR → RGB for Gradio
    im_rgb = im_bgr[..., ::-1]

    return im_rgb


# -------------------------
# Gradio UI
# -------------------------
app = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="numpy", label="Upload Image"),
    outputs=gr.Image(type="numpy", label="Detection Result"),
    title="Buck Tracker AI – Deer Detection",
    description="YOLO-based buck vs doe detection using Ultralytics native plotting."
)

# -------------------------
# Launch
# -------------------------
if __name__ == "__main__":
    app.launch()