Views
No views yet
1import gradio as gr
2from transformers import EfficientNetImageProcessor, EfficientNetForImageClassification
3from PIL import Image
4import torch
5
6# Load model and processor
7model_name = "VinayHajare/EfficientNetB0-finetuned-Marathi-Sign-Language"
8model = EfficientNetForImageClassification.from_pretrained(model_name)
9processor = EfficientNetImageProcessor.from_pretrained.from_pretrained(model_name)
10
11# Marathi label mapping
12id2label = {
13 "0": "अ", "1": "आ", "2": "इ", "3": "ई", "4": "उ", "5": "ऊ",
14 "6": "ए", "7": "ऐ", "8": "ओ", "9": "औ", "10": "क", "11": "क्ष",
15 "12": "ख", "13": "ग", "14": "घ", "15": "च", "16": "छ", "17": "ज",
16 "18": "ज्ञ", "19": "झ", "20": "ट", "21": "ठ", "22": "ड", "23": "ढ",
17 "24": "ण", "25": "त", "26": "थ", "27": "द", "28": "ध", "29": "न",
18 "30": "प", "31": "फ", "32": "ब", "33": "भ", "34": "म", "35": "य",
19 "36": "र", "37": "ल", "38": "ळ", "39": "व", "40": "श", "41": "स", "42": "ह"
20}
21
22def classify_marathi_sign(image):
23 image = Image.fromarray(image).convert("RGB")
24 inputs = processor(images=image, return_tensors="pt")
25
26 with torch.no_grad():
27 outputs = model(**inputs)
28 logits = outputs.logits
29 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
30
31 prediction = {
32 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
33 }
34
35 return prediction
36
37# Gradio Interface
38iface = gr.Interface(
39 fn=classify_marathi_sign,
40 inputs=gr.Image(type="numpy"),
41 outputs=gr.Label(num_top_classes=5, label="Marathi Sign Classification"),
42 title="Marathi-Sign-Language-Detection",
43 description="Upload an image of a Marathi sign language hand gesture to identify the corresponding character."
44)
45
46if __name__ == "__main__":
47 iface.launch()
48