import streamlit as st from transformers import pipeline 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 using the pipeline pipe = pipeline("image-classification", model="Falconsai/nsfw_image_detection") # 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}")