Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification | |
from PIL import Image | |
# Title of the web app | |
st.title("NSFW Image Detection with Hugging Face") | |
# Description | |
st.write(""" | |
This is a simple web application that uses a Hugging Face model to detect NSFW content in images. | |
Upload an image and the model will classify whether it contains NSFW content. | |
""") | |
# Upload image | |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
if uploaded_file is not None: | |
# Display the uploaded image | |
image = Image.open(uploaded_file) | |
st.image(image, caption="Uploaded Image", use_column_width=True) | |
# Load the model and processor | |
processor = AutoImageProcessor.from_pretrained("Falconsai/nsfw_image_detection") | |
model = AutoModelForImageClassification.from_pretrained("Falconsai/nsfw_image_detection") | |
# Use the pipeline for image classification | |
pipe = pipeline("image-classification", model=model, feature_extractor=processor) | |
# Classify the image | |
with st.spinner('Classifying...'): | |
results = pipe(image) | |
# Display the classification results | |
st.write("Classification Results:") | |
for result in results: | |
st.write(f"Label: {result['label']}, Score: {result['score']:.4f}") | |