Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,28 +7,27 @@ import os
|
|
| 7 |
def load_model(repo_id):
|
| 8 |
download_dir = snapshot_download(repo_id)
|
| 9 |
print(download_dir)
|
| 10 |
-
path
|
| 11 |
print(path)
|
| 12 |
detection_model = YOLO(path, task='detect')
|
| 13 |
return detection_model
|
| 14 |
|
| 15 |
-
|
| 16 |
-
def predict(pilimg):
|
| 17 |
-
|
| 18 |
source = pilimg
|
| 19 |
-
|
| 20 |
-
# print(x.shape)
|
| 21 |
-
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
| 22 |
img_bgr = result[0].plot()
|
| 23 |
-
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB
|
| 24 |
-
|
| 25 |
return out_pilimg
|
| 26 |
|
| 27 |
-
|
| 28 |
REPO_ID = "sensura/belisha-beacon-zebra-crossing-yoloV8"
|
| 29 |
detection_model = load_model(REPO_ID)
|
| 30 |
|
| 31 |
-
gr.Interface(
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def load_model(repo_id):
|
| 8 |
download_dir = snapshot_download(repo_id)
|
| 9 |
print(download_dir)
|
| 10 |
+
path = os.path.join(download_dir, "best_int8_openvino_model")
|
| 11 |
print(path)
|
| 12 |
detection_model = YOLO(path, task='detect')
|
| 13 |
return detection_model
|
| 14 |
|
| 15 |
+
def predict(pilimg, conf_threshold, iou_threshold):
|
|
|
|
|
|
|
| 16 |
source = pilimg
|
| 17 |
+
result = detection_model.predict(source, conf=conf_threshold, iou=iou_threshold)
|
|
|
|
|
|
|
| 18 |
img_bgr = result[0].plot()
|
| 19 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # Convert BGR to RGB for PIL
|
|
|
|
| 20 |
return out_pilimg
|
| 21 |
|
|
|
|
| 22 |
REPO_ID = "sensura/belisha-beacon-zebra-crossing-yoloV8"
|
| 23 |
detection_model = load_model(REPO_ID)
|
| 24 |
|
| 25 |
+
gr.Interface(
|
| 26 |
+
fn=predict,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Image(type="pil", label="Upload Image"),
|
| 29 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.5, step=0.05, label="Confidence Threshold"),
|
| 30 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.6, step=0.05, label="IoU Threshold")
|
| 31 |
+
],
|
| 32 |
+
outputs=gr.Image(type="pil", label="Detection Output")
|
| 33 |
+
).launch(share=True)
|