Skip to content

Commit

Permalink
adding nsfwcheck returning booleans for the api instead of just scores
Browse files Browse the repository at this point in the history
  • Loading branch information
amshrbo committed Jul 4, 2021
1 parent 8afa7d1 commit 5692e4b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
29 changes: 22 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
import os, shutil
from helpers.nsfwDetection import nsfw_detection
from helpers.nudityDetection import nude_detection
from helpers.nsfwCheck import nsfw_check

savingFolder = './uploadedImgs'
app = Flask(__name__)

def get_preds(img_path):
value = nude_detection(img_path)
unsafe_score = value[img_path]['unsafe']

nsfw_preds = nsfw_detection(img_path)

unsafe_score = value[img_path]['unsafe']
unsafe_score = int(unsafe_score * 100)

isContainNudity = False
if unsafe_score > 85:
isContainNudity = True

preds = {
'nude_score': int(unsafe_score * 100),
'drugs_score': int(nsfw_preds[0][0] * 100),
'nude_score': unsafe_score,
# 'drugs_score': int(nsfw_preds[0][0] * 100),
'violence_score': int(nsfw_preds[0][1] * 100),
'natural_score': int(nsfw_preds[0][2] * 100)
}
# print(preds)

return preds

Expand Down Expand Up @@ -51,8 +57,17 @@ def uploaded_imgs():

print("___Deleting files____")
delete_imgs()

return jsonify(all_results)

boleans = nsfw_check(all_results)
print(boleans)

return jsonify(
data = all_results,
isContainNude = boleans['nude'],
isContainViolence = boleans['violence']
# isContainDrugs = boleans['drugs']
)


def delete_imgs():
for imgname in os.listdir(savingFolder):
Expand Down
21 changes: 21 additions & 0 deletions helpers/nsfwCheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def nsfw_check(results):
content = {
'nude': False,
'violence': False
# 'drugs': False
}

for res in results:
if res['preds']['nude_score'] >= 80:
content['nude'] = True

# if res['preds']['drugs_score'] > 35 and res['preds']['natural_score'] < 25:
# content['drugs'] = True

if res['preds']['violence_score'] > 35 and res['preds']['natural_score'] < 25:
content['violence'] = True

if res['preds']['violence_score'] > 39:
content['violence'] = True

return content

0 comments on commit 5692e4b

Please sign in to comment.