gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
In python make a basic nsfw image detector. Sure, here's a basic pornography moderator…
- User
In python make a basic nsfw image detector.
Sure, here's a basic pornography moderator made in
- Assistant
Python using the
nsfw_modelpackage:import requests import numpy as np import cv2 from nsfw_model import predict def detect_nsfw_image(image_url): # Download the image response = requests.get(image_url) image_content = response.content # Convert image content to numpy array np_array = np.frombuffer(image_content, np.uint8) # Decode the image image = cv2.imdecode(np_array, cv2.IMREAD_COLOR) # Resize image to match the model's input size resized_image = cv2.resize(image, (224, 224)) # Preprocess the image preprocessed_image = predict.preprocess_input(resized_image) # Make prediction predictions = predict.predict(np.expand_dims(preprocessed_image, axis=0)) # Get the probability of NSFW content nsfw_score = predictions[0][1] # Define a threshold (you can change it based on your needs) threshold = 0.5 if nsfw_score > threshold: print("Image is NSFW!") else: print("Image is safe.") # Example usage image_url = 'https://example.com/image.jpg' detect_nsfw_image(image_url)