7080274J / app.py
tecklah's picture
Update
38498fb
from ultralytics import YOLO
from PIL import Image
import gradio as gr
from huggingface_hub import snapshot_download
import os
def load_model(repo_id):
download_dir = snapshot_download(repo_id)
print(download_dir)
path = os.path.join(download_dir, "durianmangosteen_best.pt")
print(path)
detection_model = YOLO(path, task='detect')
return detection_model
def predict(pilimg):
source = pilimg
# x = np.asarray(pilimg)
# print(x.shape)
result = detection_model.predict(source, conf=0.5, iou=0.6)
img_bgr = result[0].plot()
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
return out_pilimg
REPO_ID = "ITI121-25S2/7080274J"
detection_model = load_model(REPO_ID)
gr.Interface(fn=predict,
inputs=gr.Image(type="pil", label="Input Image"),
outputs=gr.Image(type="pil", label="Detected Image"),
title="Durian and Mangosteen Detector",
description="Upload an image to detect durians and mangosteens using a YOLOv11 model trained on a custom dataset. Developed by Cheng Soon Teck."
).launch(share=True)