File size: 843 Bytes
665336c
 
 
 
 
 
1f62fd2
665336c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from ultralytics import YOLO
import cv2
import numpy as np

# Load the trained Mudra model
model = YOLO("best.pt")  # path inside the Space

def predict_mudra(image):
    # Convert to RGB if needed
    img_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    
    # Run classification
    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}%)"

# Gradio interface
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()