|
import numpy as np |
|
from PIL import Image |
|
import gradio as gr |
|
from ultralytics import YOLO |
|
|
|
|
|
m_raw_model = YOLO("M-Raw.pt") |
|
n_raw_model = YOLO("N-Raw.pt") |
|
s_raw_model = YOLO("S-Raw.pt") |
|
|
|
def snap(image, model, conf): |
|
|
|
image = np.array(image) |
|
|
|
|
|
results = None |
|
if model == "M-Raw": |
|
results = m_raw_model(image, conf=conf) |
|
elif model == "N-Raw": |
|
results = n_raw_model(image, conf=conf) |
|
elif model == "S-Raw": |
|
results = s_raw_model(image, conf=conf) |
|
|
|
|
|
resulting_image = results.render() |
|
|
|
|
|
resulting_image = Image.fromarray(resulting_image) |
|
|
|
|
|
labels = results.pandas().xyxy[0]["name"].values |
|
|
|
|
|
labels = labels[np.argsort(results.pandas().xyxy[0]["x"].values)] |
|
|
|
return [resulting_image, labels] |
|
|
|
|
|
demo = gr.Interface( |
|
snap, |
|
[gr.Image(source="webcam", tool=None, streaming=True), gr.inputs.Radio(["M-Raw", "N-Raw", "S-Raw"]), gr.inputs.Slider(0.0, 1.0, 0.5, 0.1, "Confidence")], |
|
["image", "labels"], |
|
title="Baybayin Instance Detection" |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |