baiduai.py 844 B

123456789101112131415161718192021222324252627282930313233343536
  1. #-*-coding:utf-8 -*-
  2. from aip import AipContentCensor
  3. APP_ID = "33751511"
  4. API_KEY = "gd8nik5KMNIbh76KGqYbFOCc"
  5. SECRET_KEY = "1m6HfzQVURFcu9ghmFHPje587slp5XG6"
  6. def get_file_content(filePath):
  7. with open(filePath, 'rb') as fp:
  8. return fp.read()
  9. def baidu_ai_detect_image(imgpath):
  10. """
  11. """
  12. client = AipContentCensor(APP_ID, API_KEY, SECRET_KEY)
  13. if "http://" or "https://" in imgpath:
  14. result = client.imageCensorUserDefined(imgpath)
  15. else:
  16. result = client.imageCensorUserDefined(get_file_content(imgpath))
  17. return result
  18. def baidu_ai_detect_txt(content):
  19. """
  20. """
  21. client = AipContentCensor(APP_ID, API_KEY, SECRET_KEY)
  22. result = client.textCensorUserDefined(content)
  23. return result
  24. if __name__ == "__main__":
  25. imgpath = "/tmp/test.png"
  26. baidu_ai_detect_image(imgpath)