Spaces:
Sleeping
Sleeping
Shabbir-Anjum
commited on
Commit
•
f6475f8
1
Parent(s):
fccd456
Rename qpp.py to app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Title of the web app
|
6 |
+
st.title("NSFW Image Detection with Hugging Face")
|
7 |
+
|
8 |
+
# Description
|
9 |
+
st.write("""
|
10 |
+
This is a simple web application that uses a Hugging Face model to detect NSFW content in images.
|
11 |
+
Upload an image and the model will classify whether it contains NSFW content.
|
12 |
+
""")
|
13 |
+
|
14 |
+
# Upload image
|
15 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
16 |
+
|
17 |
+
if uploaded_file is not None:
|
18 |
+
# Display the uploaded image
|
19 |
+
image = Image.open(uploaded_file)
|
20 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
21 |
+
|
22 |
+
# Load the model and processor
|
23 |
+
processor = AutoImageProcessor.from_pretrained("Falconsai/nsfw_image_detection")
|
24 |
+
model = AutoModelForImageClassification.from_pretrained("Falconsai/nsfw_image_detection")
|
25 |
+
|
26 |
+
# Use the pipeline for image classification
|
27 |
+
pipe = pipeline("image-classification", model=model, feature_extractor=processor)
|
28 |
+
|
29 |
+
# Classify the image
|
30 |
+
with st.spinner('Classifying...'):
|
31 |
+
results = pipe(image)
|
32 |
+
|
33 |
+
# Display the classification results
|
34 |
+
st.write("Classification Results:")
|
35 |
+
for result in results:
|
36 |
+
st.write(f"Label: {result['label']}, Score: {result['score']:.4f}")
|
qpp.py
DELETED
File without changes
|