def is_nude(fileName): nudity = Nudity() nude_ret = nudity.has(fileName) # gives you True or False #print(nudity.score(fileName)) return nude_ret
def __init__(self, username, password): self.username = username self.password = password self.nudity = Nudity() self.instagram_api = InstagramAPI(username, password) self.instagram_api.login() if self.instagram_api.LastJson['status'] == "fail": print(Fore.RED + self.instagram_api.LastJson['message'] + Fore.RED) sys.exit()
def check_pornographic_content(image_path): nudity = Nudity() # returns True or False is_offensive = nudity.has(image_path) # gives nudity / inappropriate content score between 0.0 - 1.0 score = nudity.score(image_path) print(is_offensive) if score < 0.0001: score = 0.0 print(score) return [is_offensive, score]
def longLoading(loop, message, file): try: nudity = Nudity() if nudity.has(file): loop.create_task(message.edit("nude detected..")) else: loop.create_task(message.edit("no nude detected..")) if file != None: os.remove(file) except Exception as e: loop.create_task(message.edit(str(e))) if file != None: os.remove(file)
HOST = 'localhost' # Standard loopback interface address (localhost) PORT = 5678 # Port to listen on (non-privileged ports are > 1023) sys.stdout = sys.stderr = open('/var/log/wevip', 'a') os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # Disables tensorflow spamflow from nudity import Nudity with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen() while True: conn, addr = s.accept() with conn: print('Connected by', addr) while True: data = conn.recv(1024).strip() if not data: break else: print("Received", data) image = data.decode() nudity = Nudity() if nudity.has(image): print("P**n") conn.sendall(b'1') else: print("Clear") conn.sendall(b'0') sys.stdout.flush()
import shutil cur_dir = [i for i in os.listdir('C:/Users/Lenovo/Desktop/nodyab')] print(cur_dir) for i in cur_dir: if 'mamad' in i: os.remove(i) elif 'nude' in i: os.remove(i) def sayy(text): engine = pyttsx3.init() engine.say(text) engine.runAndWait() nudity = Nudity() threshold = 0 while True: img = ImageGrab.grab() img.save('images_trash/mamad.png') Has_nude = nudity.has('images_trash/mamad.png') threshold = threshold + 1 if Has_nude == True: os.rename('images_trash/mamad.png','nude%s.png'%threshold) try: shutil.move('C:/Users/Lenovo/Desktop/nodyab/nude%s.png'%threshold,'C:/Users/Lenovo/Desktop/nuudes') except: thresholdnew = threshold+1 shutil.move('C:/Users/Lenovo/Desktop/nodyab/nude%s.png'%threshold,'C:/Users/Lenovo/Desktop/nuudes/nuude%s.png'%thresholdnew) print('shit')
import tweepy from tweepy import OAuthHandler import os from nudity import Nudity from colorama import Fore from urllib.request import urlopen from urllib.request import urlretrieve from datetime import datetime import utilsy nudity = Nudity() utilssy = utilsy.Utilsy() #hashtag = "" class Twitter: def __init__(self, consumer_key, consumer_secret, access_token, access_secret): auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_secret) self.api = tweepy.API(auth) hashtag = "" self.hashtag = hashtag def check_user(self, username, stop, nude=False, firearm=False): tweets = self.api.user_timeline(screen_name=username, count=200, include_rts=False, exclude_replies=True,
class Instagram: def __init__(self, username, password): self.username = username self.password = password self.nudity = Nudity() self.instagram_api = InstagramAPI(username, password) self.instagram_api.login() if self.instagram_api.LastJson['status'] == "fail": print(Fore.RED + self.instagram_api.LastJson['message'] + Fore.RED) sys.exit() def check_location(self, lat, lng, nudes=False,firearm=False): self.instagram_api.geosearchLocations(lat, lng) print("Looking for photos nearby " + Fore.GREEN + str(lat) + ", " + str(lng) + Fore.RESET) last1 = self.instagram_api.LastJson if not os.path.exists('location/'): os.mkdir('location/') print("Places: ") for place in last1['venues']: if place['address']: print(Fore.LIGHTBLUE_EX + place['address'] + Fore.RESET) for place in last1['venues']: c = 0 print("Checking " + Fore.LIGHTBLUE_EX + place['address'] + Fore.RESET) self.instagram_api.getLocationFeed(place['external_id']) last2 = self.instagram_api.LastJson # try: # print("Found " + Fore.CYAN + str(len(last2['items'])) + Fore.RESET+ " results") # except Exception as e: # break if not os.path.exists('location' + "/" + place['address']): os.mkdir('location' + "/" + place['address']) if not os.path.exists('location' + "/" + place['address'] + "/artifacts"): os.mkdir('location/' + place['address'] + "/artifacts") for photo in last2['items']: if 'carousel_media' in photo: # only carousel media? try: print("[i] Downloading " + photo['carousel_media'][0]['image_versions2']['candidates'][0][ 'url'] + " to " + 'location/' + Fore.YELLOW + place['address'] + "/" + photo['user']['username'] + ".jpg" + Fore.RESET) urlretrieve(photo['carousel_media'][0]['image_versions2']['candidates'][0][ 'url'],'location' + "/" + place['address'] + "/" +photo['user']['username']+ ".jpg") if nudes: score = self.nudity.score('location' + "/" + place['address'] + "/" +photo['user']['username']+ ".jpg") print("Detected score: " + Fore.CYAN + str(round(score, 4)) + Fore.RESET) if score > 0.5: print(Fore.RED + " Found nude") print( " Timestamp: " + Fore.RED + str( datetime.utcfromtimestamp(photo['taken_at']).strftime('%Y-%m-%d %H:%M:%S')) + Fore.RED) print(Fore.LIGHTCYAN_EX + " " + photo['user']['username'] + Fore.RESET) if photo['caption'] is not None: print(" Text:" + photo['caption']['text']) # print(" Text:" + photo['caption']['text']) print(" Moving to /artifacts") try: os.rename('location' + "/" + place['address'] + "/" + photo['user']['username'] + ".jpg", 'location' + "/" + place['address'] + "/artifacts/" + "" + photo['user']['username'] + ".jpg") except Exception as e: print (e.args) else: print(Fore.GREEN + " No nude" + Fore.RESET) elif firearm: detection = utilssy.detect_firearm( image_path="location" + "/" + place['address'] + "/" + photo['user']['username'] + ".jpg", output_path="location" + "/" + place['address'] + "/" + photo['user']['username'] + "_box.jpg") c = c + 1 except Exception as e: print(e.with_traceback()) def check_hashtag(self,hashtag, nudes=False,firearm=False): req = urlopen("https://www.instagram.com/explore/tags/" + hashtag + "/?__a=1") json_req = json.loads(req.read()) c = 0 if not os.path.exists('hashtags'): os.mkdir('hashtags') if not os.path.exists("hashtags/"+hashtag): os.mkdir("hashtags/"+hashtag) if not os.path.exists("hashtags/"+hashtag + "/artifacts"): os.mkdir("hashtags/"+hashtag + "/artifacts") for i in json_req['graphql']['hashtag']['edge_hashtag_to_top_posts']['edges']: try: print( "[i] Downloading " + i['node']['display_url'] + Fore.YELLOW +" to hashtags/" + hashtag + "/" + i['node']['owner']['id'] + ".jpg" + Fore.RESET) urlretrieve(i['node']['display_url'], "hashtags/"+hashtag + "/"+i['node']['owner']['id'] + ".jpg") if nudes: score = self.nudity.score("hashtags/"+ hashtag + "/" +i['node']['owner']['id'] + ".jpg") print("Detected score: " + Fore.CYAN + str(round(score, 4)) + Fore.RESET) if score > 0.5: print(Fore.RED + " Found nude" + Fore.RESET) print(" Timestamp: " + Fore.RED + str( datetime.utcfromtimestamp(i['node']['taken_at_timestamp']).strftime('%Y-%m-%d %H:%M:%S')) + Fore.RESET) # print(" Access:" + i['node']['accessibility_caption']) print(" Owner: " + Fore.LIGHTMAGENTA_EX + i['node']['owner']['id'] + Fore.RESET) self.instagram_api.getUsernameInfo(i['node']['owner']['id']) print(" Username: "******" Full name: " + Fore.LIGHTRED_EX + self.instagram_api.LastJson['user']['full_name'] + Fore.RESET) print(" Bio: " + self.instagram_api.LastJson['user']['biography']) print(" Url: " + self.instagram_api.LastJson['user']['external_url']) print(" Moving to /artifacts") os.rename("hashtags/"+hashtag + "/" +i['node']['owner']['id'] + ".jpg", "hashtags/"+hashtag + "/artifacts/" +self.instagram_api.LastJson['user']['username']+ ".jpg") elif firearm: self.instagram_api.getUsernameInfo(i['node']['owner']['id']) detection = utilssy.detect_firearm(image_path="hashtags/" + hashtag + "/"+i['node']['owner']['id'] + ".jpg", output_path="hashtags/" + hashtag + "/artifacts/"+ self.instagram_api.LastJson['user']['username'] + "_box.jpg") if detection: print(" Timestamp: " + Fore.RED + str( datetime.utcfromtimestamp(i['node']['taken_at_timestamp']).strftime( '%Y-%m-%d %H:%M:%S')) + Fore.RESET) # print(" Access:" + i['node']['accessibility_caption']) print(" Owner: " + Fore.LIGHTMAGENTA_EX + i['node']['owner']['id'] + Fore.RESET) self.instagram_api.getUsernameInfo(i['node']['owner']['id']) print(" Username: "******" Full name: " + Fore.LIGHTRED_EX + self.instagram_api.LastJson['user'][ 'full_name'] + Fore.RESET) print(" Bio: " + self.instagram_api.LastJson['user']['biography']) print(" Url: " + self.instagram_api.LastJson['user']['external_url']) print(" Moving to /artifacts") except Exception as e: print(e.with_traceback()) c = c + 1 def check_user(self, username, stop, nudes=False,firearm=False): url = "https://www.instagram.com/web/search/topsearch/?context=blended&query=" + username + "&rank_token=0.3953592318270893&count=1" response = urlopen(url) respJSON = json.loads(response.read()) try: user_id = str(respJSON['users'][0].get("user").get("pk")) except Exception as e: print(e.args) sys.exit() if not os.path.exists('users'): os.mkdir('users') if not os.path.exists("users/" + username): os.mkdir("users/" + username) if not os.path.exists("users/" + username+"/artifacts"): os.mkdir("users/" + username+"/artifacts") self.instagram_api.getUsernameInfo(user_id) ########PRINT INFO############# print(self.instagram_api.LastJson['user']['username']) print(self.instagram_api.LastJson['user']['full_name']) print(self.instagram_api.LastJson['user']['biography']) print(self.instagram_api.LastJson['user']['external_url']) nextmaxid = "" rating = [] c = 0 while c < stop: self.instagram_api.getUserFeed(user_id, nextmaxid) for i in self.instagram_api.LastJson['items']: try: print("[i] Downloading " + i['image_versions2']['candidates'][0][ 'url'] + Fore.YELLOW + " to " +"users/"+ username + "/image"+str(c) + ".jpg" + Fore.RESET) urlretrieve(i['image_versions2']['candidates'][0]['url'],"users/" + username + "/" + "/image"+str(c) + ".jpg") if nudes: score = self.nudity.score("users/" +username + "/" + "/image"+str(c) + ".jpg") rating.append(score) print("Detected score: " + Fore.CYAN + str(round(score, 4)) + Fore.RESET) if score > 0.5: print(Fore.RED + " Found nude" + Fore.RESET) print(" Timestamp: " + Fore.RED + str( datetime.utcfromtimestamp(i['taken_at']).strftime( '%Y-%m-%d %H:%M:%S')) + Fore.RESET) print(" Text: " + i['caption']['text']) print(" Moving to /artifacts") os.rename("users/" +username + "/image" + str(c) + ".jpg", "users/" + username + "/artifacts/image" + str(c) + ".jpg") else: c = c + 1 elif firearm: detection = utilssy.detect_firearm( image_path="users/" + username + "/" + "/image"+str(c) + ".jpg", output_path="users/" + username + "/artifacts/" + "/image"+str(c) + "_box.jpg") if detection: print(" Timestamp: " + Fore.RED + str( datetime.utcfromtimestamp(i['taken_at']).strftime( '%Y-%m-%d %H:%M:%S')) + Fore.RESET) print(" Text: " + i['caption']['text']) print(" Moving to /artifacts") c = c + 1 else: c = c + 1 except Exception as e: print(e.args) nextmaxid = self.instagram_api.LastJson['next_max_id'] ######CAROUSEL media # if help == 0: # try: # print("[i] Downloading " + i['image_versions2']['candidates'][0][ # 'url'] + " into +" + ig_username + "/image" + str(c) + ".jpg") # urlretrieve(i['carousel_media'][0]['image_versions2']['candidates'][0]['url'], "image" + str(c) + ".jpg") # score = nudity.score(ig_username + "/image" + str(c) + ".jpg") # print("Detected score: " + str(round(score, 4))) # # print(nudity.has(ig_username + "/image" + str(c) + ".jpg")) # if nudity.has(ig_username+"image" + str(c) + ".jpg"): # print ("Found photo with " + str(round(score, 4)) + ". Moving to /artifacts") # os.rename(ig_username + "/image" + str(c) + ".jpg", ig_username + "/artifacts/image" + str(c) + ".jpg") # # print(round(score, 4)) # rating.append(score) # # print(nudity.has("image" + str(c) + ".jpg")) # except Exception as e: # print(e.args) # print (c) if nudes: avg = sum(rating) / len(rating) # avg = np.mean(rating) print("Whoregrade: " + str(avg))
def nudity_filter(file): nudity = Nudity() if nudity.has(file) == True: statement = 'image is above obscenity threshold' return(nudity.score(file), statement)
#!/usr/bin/env python import imp import os import sys sys.path.insert( 0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) from nudity import Nudity if __name__ == '__main__': nudity = Nudity() base_path = os.path.dirname(os.path.abspath(__file__)) none_samples = os.path.abspath(base_path + "/samples/none") nude_samples = os.path.abspath(base_path + "/samples/nude") for sample in os.listdir(none_samples): file_name = os.path.abspath(none_samples + "/" + sample) if False != nudity.has(file_name): print("Error: " + file_name) else: print("Success: " + file_name) for sample in os.listdir(nude_samples): file_name = os.path.abspath(nude_samples + "/" + sample) if False == nudity.has(file_name): print("Error: " + file_name) else: print("Success: " + file_name)