File size: 887 Bytes
6590ce7
4745afa
6590ce7
db7b04a
00d949a
e24712a
1a47aa3
ced9eab
 
 
e24712a
1a47aa3
 
66bc972
1a47aa3
 
66bc972
4745afa
 
 
 
00d949a
 
2a0fb5d
1a47aa3
e24712a
4745afa
6590ce7
 
4745afa
1a47aa3
e24712a
 
4745afa
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
import gradio as gr
import torch
from PIL import Image
import numpy as np
import sys, os

# ---- Add forked YOLOv12 code to Python path ----
fork_ultra_path = os.path.join(os.path.dirname(__file__), "yolov12-main", "yolov12-main", "ultralytics")
sys.path.insert(0, fork_ultra_path)


# ---- Now import YOLO from the fork, not from pip ----
from ultralytics import YOLO

# ---- Load the trained model ----
model = YOLO("best.pt")

# ---- Inference function ----
def detect_objects(image):
    img = np.array(image)
    results = model(img)
    annotated = results[0].plot()
    return Image.fromarray(annotated)

# ---- Gradio UI ----
iface = gr.Interface(
    fn=detect_objects,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil"),
    title="Ear Condition Detection (YOLOv12 Fork)",
    description="Runs inference using the sunsmarterjie YOLOv12 fork."
)

iface.launch()