Beispiel #1
0
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")
Beispiel #2
0
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']
Beispiel #3
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)
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='文章详情查询失败')
Beispiel #5
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("没有图片")
Beispiel #6
0
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'])
Beispiel #7
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)
from aip import AipImageCensor
import passwd

APP_ID = passwd.sex.APP_ID  # 你的app id , 此处被隐藏,放在pass wd.py文件内,请自行申请
API_KEY = passwd.sex.API_KEY  # 你的api key
SECRET_KEY = passwd.sex.SECRET_KEY  # 你的secret key

client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)


# 读取图片
def get_file_content(file_path):
    with open(file_path, 'rb') as fp:
        return fp.read()


# 调用色情识别接口
# result = client.imageCensorUserDefined(get_file_content('sex1.png'))
# result = client.imageCensorUserDefined(get_file_content('sex2.jpg'))
# result = client.imageCensorUserDefined(get_file_content('sex3.jpg'))
# 如果图片是url调用如下
result = client.imageCensorUserDefined(
    'https://imgsa.baidu.com/forum/w%3D580/sign=559cf2cad93f8794d3ff4826e21a0ead/f3bc0ddda3cc7cd94ac925ab3401213fb90e91eb.jpg'
)
print(result)

# 官方测试 :https://ai.baidu.com/tech/imagecensoring
Beispiel #9
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)
Beispiel #10
0
	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
Beispiel #11
0
from aip import AipImageCensor
""" 你的 APPID AK SK """
APP_ID = '10699663'
API_KEY = 'h6laYDwumS3UzwiCCjYGQPkP'
SECRET_KEY = 'd9GFQc6ntq0pBGHRv6YrFxxfEfDYq3QH'

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('cb.jpg')
result = client.imageCensorUserDefined(img)
print(result)
# if isinstance(result, dict):
#     if result.has_key('conclusion'):
#         if result['conclusion'] != u'合规':
#             for data in result['data']:
#                 print (data['msg'])
from aip import AipImageCensor
""" 你的 APPID AK SK """
APP_ID = '11156578'
API_KEY = '3K73kH6H4aGoZbUrE1N0oTO5'
SECRET_KEY = 'YoL5g6BCnWG4mQvEo0TjyDPozlySdDRp'

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('c:/code/11.jpg'))
result2 = client.imageCensorUserDefined(get_file_content('c:/code/22.jpg'))
print(result)
print(result2)
""" 如果图片是url调用如下 """
result3 = client.imageCensorUserDefined('http://www.example.com/image.jpg')
from aip import AipImageCensor

# """ 你的 APPID AK SK """
# APP_ID = '17899842'
# API_KEY = 'VM5S1ouZgwmk7Icc8x2l75pK'
# SECRET_KEY = '9Cvxl1qB4zGuidQod9Sw6zadQHcnIQZz'

""" API """
APP_ID = '19891414'  # 你的appid
API_KEY = 'usNMOs7sdzwep3QOgY4xoFV2'  # 你的apikey
SECRET_KEY = 'gw5vs1lKOLRGE6MstE8X8zbmxsXVBWIg'  # 你的secretkey


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('sex3.jpg'))
""" 如果图片是url调用如下 """
#result = client.imageCensorUserDefined('https://imgsa.baidu.com/forum/w%3D580/sign=559cf2cad93f8794d3ff4826e21a0ead/f3bc0ddda3cc7cd94ac925ab3401213fb90e91eb.jpg')
print(result)

#官方测试:
Beispiel #14
0
from aip import AipImageCensor


# 图片审核
filePath = '../media/upload/aa.jpg'


def get_picture(filePath):
    with open(filePath, 'rb') as f:
        return f.read()


APP_ID = '16295532'
API_KEY = 'gWSlD06wqf8yADLNw1PSdIhI'
SECRET_KEY = 'pqxslzYtZvoDrpEN3qtebSexw8vqDlR7'


client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)


result = client.imageCensorUserDefined(get_picture(filePath))
print(result)

if __name__ == '__main__':
    get_picture(filePath)


Beispiel #15
0
from aip import AipImageCensor

#  图片识别
APP_ID = '16295532'
API_KEY = 'gWSlD06wqf8yADLNw1PSdIhI'
SECRET_KEY = 'pqxslzYtZvoDrpEN3qtebSexw8vqDlR7'

client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)

filePath = '../media/u0.jpg'


# 图片审核
def get_file_picture(filePath):
    with open(filePath, 'rb') as f:
        return f.read()


result = client.imageCensorUserDefined(get_file_picture(filePath))
print(result)

result1s = client.imageCensorUserDefined('http://www.example.com/image.jpg')
print(result1s)
Beispiel #16
0
class ContentVerify:
    def __init__(self):
        self.client = AipImageCensor(
                current_app.config['APP_ID'],
                current_app.config['API_KEY'],
                current_app.config['SECRET_KEY']
            )

    def verify_uploaded_images(self, img):
        if isinstance(img, str):
            _, suffix = os.path.splitext(img)
            if not suffix == '.gif':
                result = self.client.imageCensorUserDefined(img)
            else:
                result = self.client.antiPornGif(img)
        else:
            filename = img.filename
            _, suffix = os.path.splitext(filename)
            if not suffix == '.gif':
                result = self.client.imageCensorUserDefined(img.read())
            else:
                result = self.client.antiPornGif(img.read())

        msg = self.extract_msg(result, suffix)
        ok_or_not = self.is_ok(msg, suffix)
        return msg, ok_or_not


    def verify_uploaded_avatar(self, avatar):
        filename = avatar.filename
        _, suffix = os.path.splitext(filename)
        result = self.client.faceAudit(avatar.read())
        msg = result['result'][0]['data']['antiporn']
        if "conclusion" in msg:
            if not msg['conclusion'] == "色情":
                return '', True
            else:
                return msg['conclusion'] + ",上传失败!", False
        else:
            return '审核失败,请重试!', False


    def verify_text(self, text):
        result = self.client.antiSpam(text)
        spam_code = result['result']['spam']
        if spam_code == 0:
            return '', spam_code, True
        elif spam_code == 1:
            return "涉及敏感词,审核未通过,提交失败!", spam_code, False
        else:
            return "待审核,您将在12小时内收到审核结果", spam_code, False



    def extract_msg(self, result, suffix):
        if "error_msg" in result:
            return [{"error_msg": result['error_msg']}]

        if not suffix == '.gif':
            if 'data' not in result.keys():
                return [""]
            data = result['data']
            msg = [d["msg"] for d in data]
            return msg
        else:
            data = result['conclusion']
            msg = [data]
            return msg

    def is_ok(self, msg, suffix):
        if isinstance(msg[0], dict):
            return False
        if not suffix == ".gif":
            return ("存在色情内容" not in msg) and ("存在政治敏感内容" not in msg)
        else:
            return "色情" not in msg