コード例 #1
0
ファイル: test.py プロジェクト: SchroDr/WhistleWind
def AipImageCensoR(filePath):
    client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
    result = client.imageCensorUserDefined(
        get_file_content(filePath))
    # result = client.imageCensorUserDefined('http://www.example.com/image.jpg')
    #print(result)
    return result['conclusionType']
コード例 #2
0
ファイル: views.py プロジェクト: Hans210302/web1
def openpic(request):
    from qiniu import Auth, put_file, etag
    import qiniu.config
    from PIL import Image
    from aip import AipImageCensor
    a = request.FILES.get("imageData")  #得到图片
    b = random.randint(111111, 999999)
    key = 's2' + str(b) + '.jpg'
    Image = Image.open(a)
    Image.save('s1.jpg')  #保存本地
    APP_ID = '10027473'
    API_KEY = 'vuVlmlKsXULFfo438jiWfxb0'
    SECRET_KEY = '33Iew8K4zT3hBBI1YqGPaK9vcHD5dAxG'
    client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)

    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()

    img = get_file_content('s1.jpg')
    result = client.imageCensorUserDefined(img)
    if result['conclusion'] == '合规':
        # path = default_storage.save('s1.jpg', ContentFile(Image.read()))

        access_key = 'EjIqvG2iluFxOx-PzeIyCNUKqUL2je9Q5bfunOyg'
        secret_key = 'pqt97zqOt7cw07a9AWwEXPp0zofB_9swvTVJGOOr'
        q = Auth(access_key, secret_key)
        bucket_name = 'xunyingpicture'
        localfile = r"s1.jpg"
        token = q.upload_token(bucket_name, key)
        ret, info = put_file(token, key, localfile)
        #返回图片地址
        return HttpResponse('http://files.g8.xmgc360.com/' + key)
    else:
        return HttpResponse("1")
コード例 #3
0
def bad_words_filter(img_name):

    base_name = img_name.split('\\')[-1]
    text = ' '
    with open('data/results/' + 'res_{}.txt'.format(base_name.split('.')[0]),
              'r') as f:
        # text = f.read().split('\n')
        text = ' '
        # for i in text:
        #     temp += i
        lines = f.readlines()
        for line in lines:
            str_arr = line.strip().split(',')
            if len(str_arr) > 4:
                for word in str_arr[4:]:
                    text += (word + ',')

    with open('data/results/' + 'res_{}.txt'.format(base_name.split('.')[0]),
              'a') as f:
        client = AipImageCensor(appId='18097522',
                                apiKey='bgeRXmpblbOMocErTxvMCiOF',
                                secretKey='SyRmwoFGsKXqC3LvAAYwlDlf1BckBOwG')
        if client.antiSpam(text)['result']['spam'] == 0:
            f.write('无敏感信息')
        else:
            f.write('待检测的文本里面含有侮辱、色情、暴力和政治敏感词汇。\n')
            for i in client.antiSpam(text)['result']['reject']:
                if (len(i['hit']) != 0):
                    f.write(str(i['hit']))
コード例 #4
0
ファイル: Util.py プロジェクト: wanghaoyu33437/ICare
 def __init__(self):
     # 测试数据
     test_case = [np.zeros(10)]
     print('**** Load dict ****')
     f = open(config._URL['URL_DICT_PATH'], encoding='utf8')
     char = f.read()
     url_dict = eval(char)
     f = open(config._DGA['DGA_DICT_PATH'], encoding='utf8')
     char = f.read()
     dga_dict = eval(char)
     f.close()
     self.DGA_dict = dga_dict
     self.Url_dict = url_dict
     # 文本检测返回值
     self.URL_labels = ['暴恐违禁', '文本色情', '政治敏感', '恶意推广', '低俗辱骂', '低质灌水']
     print('**** Load model ****')
     ''' 创建加载模型的所需变量'''
     self.graph1 = tf.Graph()
     self.sess1 = tf.Session(graph=self.graph1)
     self.graph2 = tf.Graph()
     self.sess2 = tf.Session(graph=self.graph2)
     '''保证模型加载在一个图中,以便再使用模型时不为空'''
     with self.sess1.as_default():
         with self.graph1.as_default():
             self.DGAModel = tf.keras.models.load_model(
                 config._DGA['DGA_MODEL_PATH'])
             # 初始化的时候要进行一次模拟测试,防止layer找不到
             test_case = tf.keras.preprocessing.sequence.pad_sequences(
                 test_case,
                 maxlen=self.DGA_dict['maxlen'],
             )
             self.DGAModel.predict(test_case, verbose=0)
             print('DGA模型初始化成功')
     keras.backend.clear_session()
     with self.sess2.as_default():
         with self.graph2.as_default():
             self.UrlModel = keras.models.load_model(
                 config._URL['URL_MODEL_PATH'])
             test_case = keras.preprocessing.sequence.pad_sequences(
                 test_case,
                 maxlen=self.Url_dict['maxlen'],
             )
             self.UrlModel.predict(test_case, verbose=0)
             print('URL模型初始化成功')
     self.iface = config.IFACE
     self.DGA_Flag = 1
     self.URL_Flag = 1
     self.mydb = connect(host='localhost',
                         user='******',
                         passwd='123456',
                         database='dgamonitoring')
     print('**** Connect mysql ****')
     self.Mycursor = self.mydb.cursor()
     self.mysqlPool = self.MysqlPool()
     print('**** Connect success ****')
     self.client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
     pass
コード例 #5
0
ファイル: utils.py プロジェクト: wemecan/DjangoForum
def contentany(content):
    client = AipImageCensor('百度ai自己申请', '百度ai自己申请', '百度ai自己申请')
    result = client.textCensorUserDefined(content)
    result = json.loads(str(result).replace("'", '"'))
    if "error_code" in result:
        return result["error_msg"]
    if result["conclusionType"] != 1 \
            and result["conclusionType"] != 3:
        return result["data"][0]["msg"]
    return False
コード例 #6
0
def test_article_filter():
    try:
        res = request.get_json()
        article_id = res.get('article_id')
        article_images = res.get('article_images')

        Logging.logger.info('request_args:{0}'.format(res))
        if not article_id:
            return jsonify(errno=-1, errmsg='参数错误,请传入要查询的文章的article_id')

        article = Article.query.get(article_id)
        if not article:
            return jsonify(errno=-1, errmsg='参数错误,该文章不存在')

        docs = mongo_store.articles.find({'title': article.title})
        doc = docs[0]
        article_dict = dict()
        content = doc.get('content')
        title = article.title.encode("utf-8")
        article_dict['title'] = title
        article_dict['content'] = content

        obj = SensitiveFilter()
        str11 = ''.join(
            [item.get('text') for item in content if item.get('text')])
        text = {'content': str11}
        txt_data = obj.content_check(text)
        if txt_data.get('errcode') == 40001:
            redis_store.delete('access_token')
            txt_data = obj.content_check(text)
        Logging.logger.info('res_data:{0}'.format(txt_data))

        APP_ID = '15791531'
        API_KEY = 'kajyVlP73XtSGBgoXDIHH5Za'
        SECRET_KEY = 'u2TClEW6LaHIIpRNdFcL2HIexcgG1ovC'

        client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
        txt_resp = client.antiSpam(str11)
        Logging.logger.info('txt_resp:{0}'.format(txt_resp))

        for img in article_images:
            img_resp = client.imageCensorUserDefined(img)
            print(img_resp)
            Logging.logger.info('img_resp:{0}'.format(img_resp))
            # img_data = obj.img_check(img)
            # print img_data
        return jsonify(errno=0, errmsg="OK", data=txt_data)
    except Exception as e:
        Logging.logger.error('errmsg:{0}'.format(e))
        return jsonify(errno=-1, errmsg='文章详情查询失败')
コード例 #7
0
    def __init__(self,
                 credential,
                 bounds=(0, 255),
                 channel_axis=3,
                 preprocessing=(0, 1)):

        from aip import AipImageCensor
        super(AipAntiPornModel, self).__init__(credential=credential,
                                               bounds=bounds,
                                               channel_axis=channel_axis,
                                               preprocessing=preprocessing)

        self._task = 'cls'
        self.model = AipImageCensor(self._appId, self._apiKey, self._secretKey)
コード例 #8
0
def picture_review(content):
    pic = re.findall(r"<img src=(.*?)data", content)
    h = 0
    l = len(pic)
    client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
    if l > 0:
        for i in range(l):
            url = pic[0][1:-2]
            result = client.imageCensorUserDefined(url)
            print(result)
            if len(result['conclusion']) == 2:
                h += 1
        print("图片通过:%d") % h
        print("图片违规:%d") % (l - h)
    else:
        print("没有图片")
コード例 #9
0
ファイル: function.py プロジェクト: Leoleocheng/MEETJINN
def baiduimg(s):
    """ 你的 APPID AK SK """
    APP_ID = '14440883'
    API_KEY = 'kT8o0IxopsPwp8dswWCV54ww'
    SECRET_KEY = '8jPrgXlKj7c2mvDtkeqcTQe83RhdKLzV'
    client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)

    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()

    result = client.imageCensorUserDefined(get_file_content(r's1.' + s))
    print(result)
    if str(result['conclusionType']) == '1':
        return ('1')
    else:
        return (result['data'][0]['msg'])
コード例 #10
0
ファイル: myocr.py プロジェクト: onlinesen/rct
 def repic():
     from aip import AipImageCensor
     APP_ID = '10805647'
     API_KEY = '4BORuFSWdXtODzh8gjFVUzKB'
     SECRET_KEY = 'uZG60psAKFxRYZuqtQdTbree4ilaaPbB'
     client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
     with open(os.getcwd() + "/tmp.png", 'rb') as fp:
         options = {
             'detect_direction': 'true',
             'language_type': 'CHN_ENG',
         }
         result = client.imageCensorComb(fp.read(), [
             'clarity',
             'antiporn',
         ])
     rrresult = json.dumps(result).decode("unicode-escape")
     print rrresult
コード例 #11
0
    def identity_picture(self, file_name, flag):
        """

        :param file_name: 一个网络图片的url, 或者一个本地图片的地址
        :param flag: 传送指定的参数‘url’ 或者  ‘local’
        :return:
        """
        s_client = AipImageCensor(self.APP_ID, self.API_KEY, self.SECRET_KEY)
        if flag == 'local':
            with open(file_name, 'rb') as f:
                try:
                    res = s_client.imageCensorUserDefined(f.read())
                    print(res)
                except TypeError:
                    raise print("类型错误")

        elif flag == 'url':
            res = s_client.imageCensorUserDefined(file_name)
            print(res)
コード例 #12
0
 def __init__(self):
     self.client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
コード例 #13
0
 def __init__(self, api):
     """
     :param api: ['15052846', 'SiU9AAGaZn2Zja7d8iSVqce5', 'P6NZ07ROvKTXFnSlDMmH4hf1smOxbfAA']
     """
     self.api = api
     self.client = AipImageCensor(*self.api)
コード例 #14
0
 def get_check_json(cls, content):
     client = AipImageCensor(cls.APP_ID, cls.API_KEY, cls.SECRET_KEY)
     return client.antiSpam(content=content)
コード例 #15
0
ファイル: urls.py プロジェクト: slxsxy/csgo_full
                password=GlobalVar.get_value('g_redis_password')))

# https://www.vaptcha.com
GlobalVar.set_value('g_vaptcha_id', '0')
GlobalVar.set_value('g_vaptcha_secretkey', '0')
websocket_clients = {}
GlobalVar.set_value('g_websocket_clients', websocket_clients)
# https://console.bce.baidu.com/

GlobalVar.set_value('g_baidu_APP_ID', '0')
GlobalVar.set_value('g_baidu_API_KEY', '0')
GlobalVar.set_value('g_baidu_APP_SECKEY', '0')
GlobalVar.set_value(
    'g_baidu_APP',
    AipImageCensor(GlobalVar.get_value('g_baidu_APP_ID'),
                   GlobalVar.get_value('g_baidu_API_KEY'),
                   GlobalVar.get_value('g_baidu_APP_SECKEY')))
websocket_urlpatterns = [
    path('websocket/room/', web_socket.websocket_main),
]
application = ProtocolTypeRouter({
    'websocket':
    AuthMiddlewareStack(URLRouter(websocket_urlpatterns)),
})
urlpatterns = [
    path('favicon.ico', serve, {'path': 'images/favicon.ico'}),
    path('ha4k1r_admin/', view.admin, name='admin_index'),
    path('bind_steam/', view.bind_steam, name='bind_steam'),
    re_path(r'^$', view.index, name='index'),
    re_path(r'^bind_steamid_process/(?P<key>\w+)/$',
            view.steam_login,
コード例 #16
0
 def jh(self, file_name):
     client = AipImageCensor(self.W_APP_ID, self.API_KEY, self.SECRET_KEY)
     res = client.imageCensorUserDefined(file_name)
     print(res)
コード例 #17
0
def initspam():
    global client1
    APP_ID = '14422159'
    API_KEY = 'psxn324sUoqFaNMjyob3FaqN'
    SECRET_KEY = 'jakFwZEk63dTPr52ibznaBXoI0To2GEs'
    client1 = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
コード例 #18
0
ファイル: wz_check.py プロジェクト: hexiaowanmei/meets
	def check_Image(self, filepath):
		Image_client = AipImageCensor(self.APP_ID, self.API_KEY, self.SECRET_KEY)
		result = Image_client.imageCensorUserDefined(self.get_file_content(filepath))
		return result
コード例 #19
0
 def __init__(self):
     self.client = AipImageCensor(
             current_app.config['APP_ID'],
             current_app.config['API_KEY'],
             current_app.config['SECRET_KEY']
         )
コード例 #20
0
ファイル: CheckSetu.py プロジェクト: Heptazhou/liqibot2
def Check_Baidu():
    imgContent, imgType = downloadImg(imgurl)
    if len(imgContent) < 5e3 or len(imgContent) > 4e6:
        return
    if imgType not in ['jpg', 'jpeg', 'png']:
        return

    from aip import AipImageCensor

    censor_APP_ID = '15708523'
    censor_API_KEY = '6USQY453ZVSjxYYej1F195IZ'
    censor_SECRET_KEY = 'r0rtrpRj8eHRnkPCfEhjOPRh2eO997Uv'

    #另一个百度账号
    if random.random() < 0:
        censor_APP_ID = '22908418'
        censor_API_KEY = 'Fz2zsXkSFmdH4BgcSwvGLeNP'
        censor_SECRET_KEY = 'VSbOwvqUNzG1cDW89O9iTnnweLvLyGGM'

    #classify_APP_ID = '17981247'
    #classify_API_KEY = '3HuleW8fwIPymQcRM1DNhigp'
    #classify_SECRET_KEY = 'LcClAOmKwGSIXR2st8ishMXUPXkiLaaI'

    censor_client = AipImageCensor(censor_APP_ID, censor_API_KEY,
                                   censor_SECRET_KEY)
    censor_result = censor_client.antiPorn(imgContent)

    #print(censor_result)
    if 'result_fine' in censor_result:
        for each in censor_result['result_fine']:
            #print('type', each['type'], 'prob', each['probability'])
            if each['class_name'] == '一般色情' and each['probability'] > 0.9:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通色情' and each['probability'] > 0.51:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == 'SM' and each['probability'] > 0.65:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '艺术品色情' and each['probability'] > 0.9:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '儿童裸露' and each['probability'] > 0.9:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '低俗' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '性玩具' and each['probability'] > 0.7:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '女性性感' and each['probability'] > 0.85:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通女性性感' and each['probability'] > 0.51:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '男性性感' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '自然男性裸露' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '亲密行为' and each['probability'] > 0.90:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通亲密行为' and each['probability'] > 0.65:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '特殊类' and each['probability'] > 0.95:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '一般正常' and each['probability'] > 1.0:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '卡通正常' and each['probability'] > 1.0:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '臀部特写' and each['probability'] > 0.85:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '裆部特写' and each['probability'] > 0.75:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '脚部特写' and each['probability'] > 0.85:
                print('色图!', end='')
                saveImg(imgurl)
                break
            elif each['class_name'] == '孕肚裸露' and each['probability'] > 0.99:
                print('色图!', end='')
                saveImg(imgurl)
                break
コード例 #21
0
#
# # """ 调用人体检测与属性识别 """
# clients.bodyAttr(image)
#
# # """ 如果有可选参数 """
# options = {}
# options["age"] = "gender,age,upper_color"
#
# # """ 带参数调用人体检测与属性识别 """
# res = clients.bodyAttr(image, options)
# # print(res)
# c = res['person_info'][0]['attributes']
# # print(c)
# for k,v in c.items():
#     print(k,v['name'])

# 图片鉴黄
s_client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """


def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


""" 调用色情识别接口 """
result = s_client.imageCensorUserDefined(
    get_file_content('images/12345678.jpg'))
print(result)
コード例 #22
0

def downloadImg(url):
    r = requests.get(url)
    return r.content


censor_APP_ID = '15708523'
censor_API_KEY = '6USQY453ZVSjxYYej1F195IZ'
censor_SECRET_KEY = 'r0rtrpRj8eHRnkPCfEhjOPRh2eO997Uv'

#classify_APP_ID = '17981247'
#classify_API_KEY = '3HuleW8fwIPymQcRM1DNhigp'
#classify_SECRET_KEY = 'LcClAOmKwGSIXR2st8ishMXUPXkiLaaI'

censor_client = AipImageCensor(censor_APP_ID, censor_API_KEY,
                               censor_SECRET_KEY)
censor_result = censor_client.antiPorn(downloadImg(imgurl))

print(censor_result)
if 'result_fine' in censor_result:
    for each in censor_result['result_fine']:
        #print('type', each['type'], 'prob', each['probability'])
        if each['class_name'] == '一般色情' and each['probability'] > 0.9:
            print('色图!', end='')
            saveImg(imgurl)
            break
        elif each['class_name'] == '卡通色情' and each['probability'] > 0.55:
            print('色图!', end='')
            saveImg(imgurl)
            break
        elif each['class_name'] == 'SM' and each['probability'] > 0.65: