Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
| 4 |
|
|
|
|
| 5 |
model_path = hf_hub_download(
|
| 6 |
repo_id="ProConceptTech/jambazisight",
|
| 7 |
filename="best.pt"
|
|
@@ -10,23 +13,43 @@ model_path = hf_hub_download(
|
|
| 10 |
model = YOLO(model_path)
|
| 11 |
|
| 12 |
def detect(image):
|
| 13 |
-
results = model(image)
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
for r in results:
|
| 17 |
for box in r.boxes:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
})
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=detect,
|
| 28 |
-
inputs=gr.Image(type="
|
| 29 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
+
from PIL import Image, ImageDraw
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
+
# Download model from your model repo
|
| 8 |
model_path = hf_hub_download(
|
| 9 |
repo_id="ProConceptTech/jambazisight",
|
| 10 |
filename="best.pt"
|
|
|
|
| 13 |
model = YOLO(model_path)
|
| 14 |
|
| 15 |
def detect(image):
|
|
|
|
| 16 |
|
| 17 |
+
image = Image.fromarray(image)
|
| 18 |
+
results = model(image, conf=0.15)
|
| 19 |
+
|
| 20 |
+
detections = []
|
| 21 |
+
draw = ImageDraw.Draw(image)
|
| 22 |
+
|
| 23 |
for r in results:
|
| 24 |
for box in r.boxes:
|
| 25 |
+
|
| 26 |
+
x1, y1, x2, y2 = box.xyxy[0].tolist()
|
| 27 |
+
conf = float(box.conf)
|
| 28 |
+
cls = int(box.cls)
|
| 29 |
+
label = model.names[cls]
|
| 30 |
+
|
| 31 |
+
detections.append({
|
| 32 |
+
"class": label,
|
| 33 |
+
"confidence": conf,
|
| 34 |
+
"bbox": [x1, y1, x2, y2]
|
| 35 |
})
|
| 36 |
|
| 37 |
+
# draw bounding box
|
| 38 |
+
draw.rectangle([x1, y1, x2, y2], outline="red", width=3)
|
| 39 |
+
draw.text((x1, y1), f"{label} {conf:.2f}", fill="red")
|
| 40 |
+
|
| 41 |
+
return image, detections
|
| 42 |
+
|
| 43 |
|
| 44 |
demo = gr.Interface(
|
| 45 |
fn=detect,
|
| 46 |
+
inputs=gr.Image(type="numpy"),
|
| 47 |
+
outputs=[
|
| 48 |
+
gr.Image(label="Detected Image"),
|
| 49 |
+
gr.JSON(label="Detections")
|
| 50 |
+
],
|
| 51 |
+
title="JambaziSight Object Detection API",
|
| 52 |
+
description="Upload an image to detect objects using the JambaziSight YOLO model."
|
| 53 |
)
|
| 54 |
|
| 55 |
demo.launch()
|