yeftakun's picture
ok
0bd2821
raw
history blame contribute delete
671 Bytes
from transformers import ViTImageProcessor, AutoModelForImageClassification
from PIL import Image
import requests
url = 'https://images-ng.pixai.art/images/orig/2339688a-b1b0-4646-9091-aea5bc17d834'
image = Image.open(requests.get(url, stream=True).raw)
processor = ViTImageProcessor.from_pretrained('AdamCodd/vit-base-nsfw-detector')
model = AutoModelForImageClassification.from_pretrained('AdamCodd/vit-base-nsfw-detector')
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
# Predicted class: sfw