File size: 1,339 Bytes
a016fc1
 
b6b3664
0d71960
 
a016fc1
0d71960
b6b3664
 
 
 
 
 
a016fc1
 
 
0d71960
 
 
 
 
 
a016fc1
 
0d71960
 
 
 
 
 
 
 
 
 
a016fc1
 
0d71960
 
 
 
 
 
a016fc1
 
 
0d71960
 
 
 
 
 
 
a016fc1
 
 
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
48
49
50
51
52
53
54
55
import gradio as gr
from ultralytics import YOLO
from huggingface_hub import hf_hub_download
from PIL import Image, ImageDraw
import numpy as np

# Download model from your model repo
model_path = hf_hub_download(
    repo_id="ProConceptTech/jambazisight",
    filename="best.pt"
)

model = YOLO(model_path)

def detect(image):

    image = Image.fromarray(image)
    results = model(image, conf=0.15)

    detections = []
    draw = ImageDraw.Draw(image)

    for r in results:
        for box in r.boxes:

            x1, y1, x2, y2 = box.xyxy[0].tolist()
            conf = float(box.conf)
            cls = int(box.cls)
            label = model.names[cls]

            detections.append({
                "class": label,
                "confidence": conf,
                "bbox": [x1, y1, x2, y2]
            })

            # draw bounding box
            draw.rectangle([x1, y1, x2, y2], outline="red", width=3)
            draw.text((x1, y1), f"{label} {conf:.2f}", fill="red")

    return image, detections


demo = gr.Interface(
    fn=detect,
    inputs=gr.Image(type="numpy"),
    outputs=[
        gr.Image(label="Detected Image"),
        gr.JSON(label="Detections")
    ],
    title="JambaziSight Object Detection API",
    description="Upload an image to detect objects using the JambaziSight YOLO model."
)

demo.launch()