1Classification Report:
2 precision recall f1-score support
3
4 Anime Picture 0.8130 0.8066 0.8098 5600
5 Hentai 0.8317 0.8134 0.8224 4180
6 Neutral 0.8344 0.7785 0.8055 5503
7 Pornography 0.9161 0.8464 0.8799 5600
8Enticing or Sensual 0.7699 0.8979 0.8290 5600
9
10 accuracy 0.8296 26483
11 macro avg 0.8330 0.8286 0.8293 26483
12 weighted avg 0.8331 0.8296 0.8298 26483
1import gradio as gr
2from transformers import AutoImageProcessor
3from transformers import SiglipForImageClassification
4from transformers.image_utils import load_image
5from PIL import Image
6import torch
7
8# Load model and processor
9model_name = "prithivMLmods/Mature-Content-Detection"
10model = SiglipForImageClassification.from_pretrained(model_name)
11processor = AutoImageProcessor.from_pretrained(model_name)
12
13# Updated labels
14labels = {
15 "0": "Anime Picture",
16 "1": "Hentai",
17 "2": "Neutral",
18 "3": "Pornography",
19 "4": "Enticing or Sensual"
20}
21
22def mature_content_detection(image):
23 """Predicts the type of content in the image."""
24 image = Image.fromarray(image).convert("RGB")
25 inputs = processor(images=image, return_tensors="pt")
26
27 with torch.no_grad():
28 outputs = model(**inputs)
29 logits = outputs.logits
30 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
31
32 predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
33
34 return predictions
35
36# Create Gradio interface
37iface = gr.Interface(
38 fn=mature_content_detection,
39 inputs=gr.Image(type="numpy"),
40 outputs=gr.Label(label="Prediction Scores"),
41 title="Mature Content Detection",
42 description="Upload an image to classify whether it contains anime, hentai, neutral, pornographic, or enticing/sensual content."
43)
44
45# Launch the app
46if __name__ == "__main__":
47 iface.launch()