|
|
import gradio as gr |
|
|
from ultralytics import YOLO |
|
|
import cv2 |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
model = YOLO("best.pt") |
|
|
|
|
|
def predict_mudra(image): |
|
|
|
|
|
img_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) |
|
|
|
|
|
|
|
|
results = model.predict(img_rgb, task="classify", imgsz=224, verbose=False) |
|
|
result = results[0] |
|
|
class_id = result.probs.top1 |
|
|
class_name = result.names[class_id] |
|
|
confidence = result.probs.top1conf.item() |
|
|
|
|
|
return f"{class_name} ({confidence*100:.1f}%)" |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=predict_mudra, |
|
|
inputs=gr.Image(type="numpy"), |
|
|
outputs=gr.Textbox(label="Detected Mudra"), |
|
|
title="Mudra Classifier", |
|
|
description="Upload a hand image and detect which Mudra it is." |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|