Views
No views yet

Vit-Mature-Content-Detection is an image classification vision-language model fine-tuned from vit-base-patch16-224-in21k for a single-label classification task. It classifies images into various mature or neutral content categories using the ViTForImageClassification architecture.
[!Note] Use this model to support positive, safe, and respectful digital spaces. Misuse is strongly discouraged and may violate platform or regional policies. This model doesn't generate any unsafe content, as it is a classification model and does not fall under the category of models not suitable for all audiences.
[!Important] Neutral = Safe / Normal
1Classification Report:
2 precision recall f1-score support
3
4 Anime Picture 0.9311 0.9455 0.9382 5600
5 Hentai 0.9520 0.9244 0.9380 4180
6 Neutral 0.9681 0.9529 0.9604 5503
7 Pornography 0.9896 0.9832 0.9864 5600
8Enticing or Sensual 0.9602 0.9870 0.9734 5600
9
10 accuracy 0.9605 26483
11 macro avg 0.9602 0.9586 0.9593 26483
12 weighted avg 0.9606 0.9605 0.9604 26483
1from datasets import load_dataset
2
3# Load the dataset
4dataset = load_dataset("YOUR-DATASET-HERE")
5
6# Extract unique labels
7labels = dataset["train"].features["label"].names
8
9# Create id2label mapping
10id2label = {str(i): label for i, label in enumerate(labels)}
11
12# Print the mapping
13print(id2label)!pip install -q transformers torch pillow gradio1import gradio as gr
2from transformers import ViTImageProcessor, ViTForImageClassification
3from PIL import Image
4import torch
5
6# Load model and processor
7model_name = "prithivMLmods/Vit-Mature-Content-Detection" # Replace with your actual model path
8model = ViTForImageClassification.from_pretrained(model_name)
9processor = ViTImageProcessor.from_pretrained(model_name)
10
11# Label mapping
12labels = {
13 "0": "Anime Picture",
14 "1": "Hentai",
15 "2": "Neutral",
16 "3": "Pornography",
17 "4": "Enticing or Sensual"
18}
19
20def mature_content_detection(image):
21 """Predicts the type of content in the image."""
22 image = Image.fromarray(image).convert("RGB")
23 inputs = processor(images=image, return_tensors="pt")
24
25 with torch.no_grad():
26 outputs = model(**inputs)
27 logits = outputs.logits
28 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
29
30 predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
31
32 return predictions
33
34# Create Gradio interface
35iface = gr.Interface(
36 fn=mature_content_detection,
37 inputs=gr.Image(type="numpy"),
38 outputs=gr.Label(label="Prediction Scores"),
39 title="Vit-Mature-Content-Detection",
40 description="Upload an image to classify whether it contains anime, hentai, neutral, pornographic, or enticing/sensual content."
41)
42
43# Launch the app
44if __name__ == "__main__":
45 iface.launch()