Downloads · 30 days
13
11% of all-time downloads
bonndi/siglip2-large-patch16-384-nsfw-detect-v5
siglip2-large-patch16-384-nsfw-detect-v5 is a machine learning model from bonndi. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Downloads · 30 days
13
11% of all-time downloads
All-time downloads
120
Public
Parameters
316M
14.8 GB on disk
Likes
0
Public
Click a slice to open those files.
.pt9.7 GB · 61%
From the Hugging Face model README
pip install -U gradio transformers pillow torch torchvision --index-url https://download.pytorch.org/whl/cu129
from transformers import AutoImageProcessor, SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch
model_name = "bonndi/siglip2-large-patch16-384-nsfw-detect-v5"
device = ("cuda" if torch.cuda.is_available() else "cpu")
model = SiglipForImageClassification.from_pretrained(model_name).to(device)
processor = AutoImageProcessor.from_pretrained(model_name)
labels = {
"0": "drawings",
"1": "hentai",
"2": "neutral",
"3": "porn",
"4": "sexy"
}
def detect_explicit_content(image):
"""Predicts content category in an uploaded image."""
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
return predictions
iface = gr.Interface(
fn=detect_explicit_content,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(label="Prediction Scores"),
title="siglip2-mini-explicit-content",
description="Upload an image to classify it as Anime, Hentai, Sensual, Pornographic, or Safe for Work."
)
if __name__ == "__main__":
iface.launch()```