예제 #1
0
def get_porn(path: str) -> float:
    # Get p**n score
    result = 0
    try:
        image = Image.open(path)
        sfw, nsfw = classify(image)
        result = nsfw
    except Exception as e:
        logger.warning(f"Get p**n error: {e}", exc_info=True)

    return result
예제 #2
0
 def process(self):
     """
     Analyze the given image
     """
     try:
         logger.debug('Start analyzing the image')
         img = Image.open(self.file_path)
         img.convert('RGB')
         self.sfw_ratio, self.nsfw_ratio = classify(img)
         logger.debug('Ended analyzing the image')
     except IOError as e:
         logger.error("Exception with PIL Image: {}".format(e.message))
         raise
     finally:
         remove(self.file_path)
예제 #3
0
 def is_nsfw(self):
     """
     Analyze the given image and return a boolean depending on the results
     of the neural network
     """
     try:
         logger.debug('Start analyzing the image')
         img = Image.open(self.file_path)
         img.convert('RGB')
         _, nsfw = classify(img)
         return nsfw > 0.7  # Consider NSFW if ratio is higher than 0.7
     except IOError as e:
         logger.error("Exception with PIL Image: {}".format(e.message))
         return False
     finally:
         remove(self.file_path)
예제 #4
0
def check():
    """
    """

    files = sys.argv[1:]
    if not files:
        print("""\
Usage:

    nsfwcheck files...

""")
        return

    for path in files:
        image = Image.open(path)
        sfw, nsfw = classify(image)

        print("It is {} that this image is suitable for work.".format(
            probs(sfw)))
        print("It is {} that this image is *not* suitable for work.".format(
            probs(nsfw)))
예제 #5
0
import PIL.Image as Image
from nsfw import classify
from sys import argv
import os

try:
    image = Image.open(argv[1])
    sfw, nsfw = classify(image)

    print(nsfw)
    os.remove(argv[1])

except Exception as err:
    print('Erro ao analisar imagem\nErr: ', err)
예제 #6
0
def analyze_file(filename):
    image = Image.open(filename)
    sfw, nsfw = classify(image)
    return nsfw
예제 #7
0
import nsfw

img = 'p**n.jpeg'
out = nsfw.classify(img)
print(out)

img = ['p**n.jpeg', 'd2.png']
out = nsfw.classify_many(img)
print(out)