# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---



# # 猜猜我的明星脸

# + active=""
# # 本范例的具体介绍请参考百度AI的文档。https://ai.baidu.com/docs#/ImageCensoring-Python-SDK/66b47ad7
# -

第一步、导入库

from aip import AipImageCensor
import json

# +
第二步、设置认证信息

注：这里用的是测试账号，有访问次数的限制，请使用自己的账号信息。
# -

""" 你的 APPID AK SK """
APP_ID = '15469649'
API_KEY = '3vZgLINSnGGEafPflkTLzkGh'
SECRET_KEY = '<KEY>'

第三步、读取图片


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


第四步、调用接口

client = AipImageCensor(APP_ID, API_KEY, SECRET_KEY)
result = client.imageCensorComb(get_file_content('luhan.jpg'),['public'])
json_str = json.dumps(result,ensure_ascii=False)
print(json_str)
name = result['result']['public']['result'][0]['stars'][0]['name']
probability = result['result']['public']['result'][0]['stars'][0]['probability']
print('====================================================')
print(f'您的撞脸明星是:{name},可信度为:{probability}')

StarcoderdataJupyterScriptsDedupFiltered