# -*- coding:utf-8 -*-
from moderation_sdk.gettoken import get_token
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.clarity_detect import clarity_detect
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-4)
    init_global_env('cn-north-4')

    #
    # access moderation detect,post data by token
    #
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/moderation-clarity-detect.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = clarity_detect(token, '', demo_data_url, 0.8)
    print(result)

    # call interface use the file
    result = clarity_detect(token, encode_to_base64('data/moderation-clarity-detect.jpg'), '', 0.8)
    print(result)
Example #2
0
# -*- coding:utf-8 -*-
from moderation_sdk.gettoken import get_token
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.moderation_image import moderation_image
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-4),China East-Shanghai1(cn-east-3), Asia Pacific-Hong Kong(ap-southeast-1)
    init_global_env('cn-north-4')

    #
    # access moderation image,post data by token
    #
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the local file
    result = moderation_image(
        token, encode_to_base64('data/moderation-terrorism.jpg'), '',
        ['p**n', 'politics', 'terrorism', 'ad'], '')
    print(result)

    # call interface use the url (token, image, url, threshold=0.95, scene=None)
    result = moderation_image(token, "", demo_data_url,
                              ['p**n', 'politics', 'terrorism', 'ad'], '')
    print(result)
Example #3
0
# -*- coding:utf-8 -*-
from moderation_sdk.gettoken import get_token
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.moderation_image import moderation_image
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-4),China East-Shanghai1(cn-east-3), CN-Hong Kong(ap-southeast-1)
    init_global_env('cn-north-4')

    #
    # access moderation image,post data by token
    #
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the local file
    result = moderation_image(token, encode_to_base64('data/moderation-terrorism.jpg'), url=None,
                              categories=['p**n', 'politics', 'terrorism', 'ad'],
                              threshold=None, moderation_rule="default")
    print(result)

    # call interface use the url (token, image, url, threshold=0.95, scene=None)
    result = moderation_image(token, image="", url=demo_data_url,
                              categories=['p**n', 'politics', 'terrorism', 'ad'],
                              threshold=None, moderation_rule="default")
    print(result)
Example #4
0
    # Services currently support North China-Beijing(cn-north-4)
    init_global_env('cn-north-4')

    #
    # access moderation distortion correct post data by ak,sk
    #
    app_key = '*************'
    app_secret = '************'

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/vat-invoice.jpg'

    #call interface use the url correction is true means do not correction
    result = distortion_correct_aksk(app_key, app_secret, '', demo_data_url, True)
    result_obj = json.loads(result)

    # If the image needs to be corrected, the corrected image will be generated in the data directory,
    # otherwise the processing result will be printed.
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'], 'data/modeation-distortion-aksk-1.png')
    else:
        print(result)

    # call interface use the file
    result = distortion_correct_aksk(app_key, app_secret, encode_to_base64('data/modeation-distortion.jpg'), '', True)
    result_obj = json.loads(result)
    # If the image needs to be corrected, the corrected image will be generated in the data directory,
    # otherwise the processing result will be printed.
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'], 'data/modeation-distortion-aksk-2.png')
    else:
        print(result)
# -*- coding:utf-8 -*-
from moderation_sdk.gettoken import get_token
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.moderation_image import moderation_image
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-1,cn-north-4), Asia Pacific-Hong Kong(ap-southeast-1)
    init_global_env('cn-north-1')

    #
    # access moderation image,post data by token
    #
    user_name = '******'
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://ais-sample-data.obs.cn-north-1.myhuaweicloud.com/terrorism.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the local file
    result = moderation_image(token, encode_to_base64('data/moderation-terrorism.jpg'), '', ['politics','terrorism'], "")
    print(result)

    # call interface use the url (token, image, url, threshold=0.95, scene=None)
    result = moderation_image(token, "", demo_data_url, ['politics','terrorism'], '')
    print(result)
    password = '******'
    account_name = '******'  # the same as user_name in commonly use

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/modeation-distortion.jpg'
    token = get_token(user_name, password, account_name)

    #call interface use the url correction is true means do not correction
    result = distortion_correct(token, '', demo_data_url, True)
    result_obj = json.loads(result)

    # If the image needs to be corrected, the corrected image will be generated in the data directory,
    # otherwise the processing result will be printed.
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'],
                            'data/modeation-distortion-token-1.png')
    else:
        print(result)

    # call interface use the file
    result = distortion_correct(
        token, encode_to_base64('data/modeation-distortion.jpg'), '', True)
    result_obj = json.loads(result)

    # If the image needs to be corrected, the corrected image will be generated in the data directory,
    # otherwise the processing result will be printed.
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'],
                            'data/modeation-distortion-token-2.png')
    else:
        print(result)
    #
    app_key = '*************'
    app_secret = '************'

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/modeation-distortion.jpg'

    #call interface use the url correction is true means do not correction
    result = distortion_correct_aksk(app_key, app_secret, '', demo_data_url,
                                     True)
    result_obj = json.loads(result)

    # If the image needs to be corrected, the corrected image will be generated in the data directory,
    # otherwise the processing result will be printed.
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'],
                            'data/modeation-distortion-aksk-1.png')
    else:
        print(result)

    # call interface use the file
    result = distortion_correct_aksk(
        app_key, app_secret, encode_to_base64('data/modeation-distortion.jpg'),
        '', True)
    result_obj = json.loads(result)
    # If the image needs to be corrected, the corrected image will be generated in the data directory,
    # otherwise the processing result will be printed.
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'],
                            'data/modeation-distortion-aksk-2.png')
    else:
        print(result)
# -*- coding:utf-8 -*-
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.moderation_image import moderation_image_aksk
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-4),China East-Shanghai1(cn-east-3) CN-Hong Kong(ap-southeast-1)
    init_global_env('cn-north-4')

    #
    # access moderation image,post data by ak,sk
    #
    app_key = '*************'
    app_secret = '************'

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'

    # call interface use the local file
    result = moderation_image_aksk(app_key, app_secret, encode_to_base64('data/moderation-terrorism.jpg'), url=None,
                                   categories=['p**n', 'politics', 'terrorism', 'ad'],
                                   threshold=None, moderation_rule='default')
    print(result)

    # call interface use the url
    result = moderation_image_aksk(app_key, app_secret, image=None, url=demo_data_url,
                                   categories=['p**n', 'politics', 'terrorism', 'ad'],
                                   threshold=None, moderation_rule='default')
    print(result)


# -*- coding:utf-8 -*-
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.clarity_detect import clarity_detect_aksk
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-4)
    init_global_env('cn-north-4')

    #
    # access moderation detect,post data by ak,sk
    #
    app_key = '*************'
    app_secret = '************'

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/moderation-clarity-detect.jpg'

    # call interface use the url
    result = clarity_detect_aksk(app_key, app_secret, '', demo_data_url, 0.8)
    print(result)

    # call interface use the file
    result = clarity_detect_aksk(app_key, app_secret, encode_to_base64('data/moderation-clarity-detect.jpg'), '', 0.8)
    print(result)
# -*- coding:utf-8 -*-
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.clarity_detect import clarity_detect_aksk
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-1)
    init_global_env('cn-north-1')

    #
    # access moderation detect,post data by ak,sk
    #
    app_key = '*************'
    app_secret = '************'

    demo_data_url = 'https://ais-sample-data.obs.cn-north-1.myhuaweicloud.com/vat-invoice.jpg'

    # call interface use the url
    result = clarity_detect_aksk(app_key, app_secret, '', demo_data_url, 0.8)
    print(result)

    # call interface use the file
    result = clarity_detect_aksk(
        app_key, app_secret,
        encode_to_base64('data/moderation-clarity-detect.jpg'), '', 0.8)
    print(result)
# -*- coding:utf-8 -*-
from moderation_sdk.utils import encode_to_base64
from moderation_sdk.moderation_image import moderation_image_aksk
from moderation_sdk.utils import init_global_env

if __name__ == '__main__':
    # Services currently support North China-Beijing(cn-north-4),China East-Shanghai1(cn-east-3) Asia Pacific-Hong Kong(ap-southeast-1)
    init_global_env('cn-north-4')

    #
    # access moderation image,post data by ak,sk
    #
    app_key = '*************'
    app_secret = '************'

    demo_data_url = 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'

    # call interface use the local file
    result = moderation_image_aksk(
        app_key, app_secret, encode_to_base64('data/moderation-terrorism.jpg'),
        '', ['p**n', 'politics', 'terrorism', 'ad'], '')
    print(result)

    # call interface use the url
    result = moderation_image_aksk(app_key, app_secret, "", demo_data_url,
                                   ['p**n', 'politics', 'terrorism', 'ad'], '')
    print(result)