Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
|
| 9 |
-
# ----
|
| 10 |
-
|
| 11 |
-
from yolov12.models.modules.attn import Attn # forked class
|
| 12 |
import ultralytics.nn.modules.block as block
|
| 13 |
-
block.AAttn = Attn #
|
| 14 |
|
| 15 |
-
# ---- Load
|
| 16 |
-
model = YOLO("best.pt") #
|
| 17 |
|
| 18 |
# ---- Inference function ----
|
| 19 |
def detect_objects(image):
|
| 20 |
-
# Convert PIL image to array
|
| 21 |
img = np.array(image)
|
| 22 |
-
# Run YOLOv12 inference
|
| 23 |
results = model(img)
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return Image.fromarray(annotated_img)
|
| 27 |
|
| 28 |
# ---- Gradio interface ----
|
| 29 |
iface = gr.Interface(
|
|
@@ -31,8 +29,7 @@ iface = gr.Interface(
|
|
| 31 |
inputs=gr.Image(type="pil"),
|
| 32 |
outputs=gr.Image(type="pil"),
|
| 33 |
title="Ear Condition Detection (YOLOv12 Fork)",
|
| 34 |
-
description="
|
| 35 |
)
|
| 36 |
|
| 37 |
-
# Launch Gradio app
|
| 38 |
iface.launch()
|
|
|
|
| 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 yolov12 fork folder to path ----
|
| 9 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "yolov12-main"))
|
| 10 |
|
| 11 |
+
# ---- Import forked Attn and patch YOLO ----
|
| 12 |
+
from yolov12.models.modules.attn import Attn # inside yolov12-main
|
|
|
|
| 13 |
import ultralytics.nn.modules.block as block
|
| 14 |
+
block.AAttn = Attn # replace original AAttn
|
| 15 |
|
| 16 |
+
# ---- Load model ----
|
| 17 |
+
model = YOLO("best.pt") # make sure best.pt is in same folder
|
| 18 |
|
| 19 |
# ---- Inference function ----
|
| 20 |
def detect_objects(image):
|
|
|
|
| 21 |
img = np.array(image)
|
|
|
|
| 22 |
results = model(img)
|
| 23 |
+
annotated = results[0].plot()
|
| 24 |
+
return Image.fromarray(annotated)
|
|
|
|
| 25 |
|
| 26 |
# ---- Gradio interface ----
|
| 27 |
iface = gr.Interface(
|
|
|
|
| 29 |
inputs=gr.Image(type="pil"),
|
| 30 |
outputs=gr.Image(type="pil"),
|
| 31 |
title="Ear Condition Detection (YOLOv12 Fork)",
|
| 32 |
+
description="Uses forked YOLOv12 model to detect ear conditions."
|
| 33 |
)
|
| 34 |
|
|
|
|
| 35 |
iface.launch()
|