Closed Usernamezhx closed 4 years ago
import os
import base64
# from PIL import Image
# from io import BytesIO
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tiia.v20190529 import tiia_client, models
def convert_base64(img_path):
with open(img_path, 'rb') as f:
base64_img = base64.b64encode(f.read()).decode('utf-8')
return base64_img
try:
cred = credential.Credential(
'xxxxxxxxxxx',
'xxxxxxxxxxx')
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-beijing", clientProfile)
req = models.DetectDisgustRequest()
# req.ImageUrl = "xxxxxxxxxxx.jpg"
req.ImageBase64 = img
resp = client.DetectDisgust(req)
print(resp.to_json_string())
except TencentCloudSDKException as err:
print(err)
Besides that. I want to know where to get the meaning of these word aa aai af afc ame asr batch bda I find the DetectDisgust function at https://github.com/TencentCloud/tencentcloud-sdk-python/blob/74cec17a22a67cf55c2d30dcf13946d00a2d3e29/tencentcloud/tiia/v20190529/tiia_client.py#L122
aa aai af afc ame asr batch bda These are product codes. It always will be the first part of domain name. For example, you've read a API document in official site, it says this API domain name is xyz.tencentcloudapi.com, then it will be xyz module in sdk. https://intl.cloud.tencent.com/document/product/213/33276 We have a document here (Chinese Simplified version), but it is not the latest (edit manually, not auto generated as sdk), might be a bit helpful: https://cloud.tencent.com/document/sdk/Description
thanks for your reply. when I want to test the detectDisgust api for about 1w local image. It will show me an error ouble free or corruption (out) .and that can not be catch by the try except.this is my code snippet:
@retry
def init():
cred = credential.Credential(
'xxxxxxxxxxxxxxxxx',
'xxxxxxxxxxxxxx')
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-beijing", clientProfile)
# req = models.DetectDisgustRequest()
return client
def process(content):
print('process {}'.format(len(res)))
feed_id = content[0]
url = content[-1]
local_path = os.path.join(base_path, os.path.basename(url))
if os.path.exists(local_path):
#req.ImageBase64 = convert_base64(local_path)
try:
req = models.DetectDisgustRequest()
req.ImageBase64 = convert_base64(local_path)
resp = client.DetectDisgust(req)
res.append([feed_id, resp.to_json_string()])
except Exception as e:
print(e)
return
if __name__ == "__main__":
res = []
client = init()
pool = ThreadPool(6)
pool.map(process, feed_list)
pool.close()
pool.join()
it can be solved by :
def process(content):
print('process {}'.format(len(res)))
feed_id = content[0]
url = content[-1]
local_path = os.path.join(base_path, os.path.basename(url))
if os.path.exists(local_path):
#req.ImageBase64 = convert_base64(local_path)
try:
cred = credential.Credential(
'xxxxxxxxxxxxxxxxx',
'xxxxxxxxxxxxxx')
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-beijing", clientProfile)
req = models.DetectDisgustRequest()
req.ImageBase64 = convert_base64(local_path)
resp = client.DetectDisgust(req)
res.append([feed_id, resp.to_json_string()])
except Exception as e:
print(e)
return
thanks very much. I can not find any example about the DetectDisgust.