
NailbitingNet is a binary image classification model based ongoogle/siglip2-base-patch16-224, designed to detect nail-biting behavior in images. Leveraging the SiglipForImageClassification architecture, this model is ideal for behavior monitoring, wellness applications, and human activity recognition.
1Classification Report:
2 precision recall f1-score support
3
4 biting 0.8412 0.9076 0.8731 2824
5 no biting 0.9271 0.8728 0.8991 3805
6
7 accuracy 0.8876 6629
8 macro avg 0.8841 0.8902 0.8861 6629
9weighted avg 0.8905 0.8876 0.8881 6629
Class 0: "biting" → The person appears to be biting their nails
Class 1: "no biting" → No nail-biting behavior detectedpip install transformers torch pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor, SiglipForImageClassification
3from PIL import Image
4import torch
5
6# Load model and processor
7model_name = "prithivMLmods/NailbitingNet"
8model = SiglipForImageClassification.from_pretrained(model_name)
9processor = AutoImageProcessor.from_pretrained(model_name)
10
11# ID to label mapping
12id2label = {
13 "0": "biting",
14 "1": "no biting"
15}
16
17def detect_nailbiting(image):
18 image = Image.fromarray(image).convert("RGB")
19 inputs = processor(images=image, return_tensors="pt")
20
21 with torch.no_grad():
22 outputs = model(**inputs)
23 logits = outputs.logits
24 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
25
26 prediction = {id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))}
27 return prediction
28
29# Gradio Interface
30iface = gr.Interface(
31 fn=detect_nailbiting,
32 inputs=gr.Image(type="numpy"),
33 outputs=gr.Label(num_top_classes=2, label="Nail-Biting Detection"),
34 title="NailbitingNet",
35 description="Upload an image to classify whether the person is biting their nails or not."
36)
37
38if __name__ == "__main__":
39 iface.launch()