myshell_nsfw_filter / README.md
zguo0525's picture
Update README.md
be9758c

Example Usage

Here's a step-by-step Python code example to classify an image:

from transformers import pipeline
import requests
from PIL import Image
from io import BytesIO

# 1. Load the pipeline for image classification
pipe = pipeline("image-classification", model="zguo0525/myshell_nsfw_filter")

# 2. Load the image into memory (assuming you have the URL for the image)
image_url = 'https://img-myshell.net/meinamix/red_hair_girl'
response = requests.get(image_url)
image = Image.open(BytesIO(response.content))

# 3. Use the pipeline to classify the image
results = pipe(image)

# 4. Print the results
label = results[0]['label']
score = results[0]['score']
print(f"{label}: {score:.4f}")