yoloKYS's picture
Update app.py
ced9eab verified
raw
history blame
887 Bytes
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()