Views
No views yet
1from transformers import pipeline
2import requests
3from PIL import Image
4from io import BytesIO
5
6# 1. Load the pipeline for image classification
7pipe = pipeline("image-classification", model="zguo0525/myshell_nsfw_filter")
8
9# 2. Load the image into memory (assuming you have the URL for the image)
10image_url = 'https://img-myshell.net/meinamix/red_hair_girl'
11response = requests.get(image_url)
12image = Image.open(BytesIO(response.content))
13
14# 3. Use the pipeline to classify the image
15results = pipe(image)
16
17# 4. Print the results
18label = results[0]['label']
19score = results[0]['score']
20print(f"{label}: {score:.4f}")