File size: 713 Bytes
4da9928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be9758c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Example Usage

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

```python
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}")
```