Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from ultralytics import YOLO
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
| 6 |
import sys, os
|
| 7 |
|
| 8 |
-
# ---- Add
|
| 9 |
-
sys.path.
|
| 10 |
|
| 11 |
-
# ----
|
| 12 |
-
from
|
| 13 |
-
import ultralytics.nn.modules.block as block
|
| 14 |
-
block.AAttn = Attn # replace original AAttn
|
| 15 |
|
| 16 |
-
# ---- Load model ----
|
| 17 |
-
model = YOLO("best.pt")
|
| 18 |
|
| 19 |
# ---- Inference function ----
|
| 20 |
def detect_objects(image):
|
|
@@ -23,13 +20,13 @@ def detect_objects(image):
|
|
| 23 |
annotated = results[0].plot()
|
| 24 |
return Image.fromarray(annotated)
|
| 25 |
|
| 26 |
-
# ---- Gradio
|
| 27 |
iface = gr.Interface(
|
| 28 |
fn=detect_objects,
|
| 29 |
inputs=gr.Image(type="pil"),
|
| 30 |
outputs=gr.Image(type="pil"),
|
| 31 |
title="Ear Condition Detection (YOLOv12 Fork)",
|
| 32 |
-
description="
|
| 33 |
)
|
| 34 |
|
| 35 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
import sys, os
|
| 6 |
|
| 7 |
+
# ---- Add forked YOLOv12 code to Python path ----
|
| 8 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "yolov12-main"))
|
| 9 |
|
| 10 |
+
# ---- Now import YOLO from the fork, not from pip ----
|
| 11 |
+
from ultralytics import YOLO
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# ---- Load the trained model ----
|
| 14 |
+
model = YOLO("best.pt")
|
| 15 |
|
| 16 |
# ---- Inference function ----
|
| 17 |
def detect_objects(image):
|
|
|
|
| 20 |
annotated = results[0].plot()
|
| 21 |
return Image.fromarray(annotated)
|
| 22 |
|
| 23 |
+
# ---- Gradio UI ----
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=detect_objects,
|
| 26 |
inputs=gr.Image(type="pil"),
|
| 27 |
outputs=gr.Image(type="pil"),
|
| 28 |
title="Ear Condition Detection (YOLOv12 Fork)",
|
| 29 |
+
description="Runs inference using the sunsmarterjie YOLOv12 fork."
|
| 30 |
)
|
| 31 |
|
| 32 |
iface.launch()
|