华为云用户手册

  • 创建文档 内容审核 作业 本章节对创建文档内容审核作业AK/SK方式使用SDK进行示例说明。 示例代码中可以使用DocumentCreateRequestData类的withUrl配置待审核的文档url,配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunCreateDocumentModerationJobRequest{} databody := &model.DocumentCreateRequestData{ Url: "http://xxx", Format: "pdf", } request.Body = &model.DocumentCreateRequest{ EventType: "default", Data: databody, } response, err := client.RunCreateDocumentModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出创建文档内容审核作业的结果。 RunCreateDocumentModerationJobResponse {"request_id": "c083957284ce1f2c0b910115d8232ec6", "job_id": "01690387200_e3dfb78d9f20463f98aee25e6895203a"} 父主题: 文档审核
  • 查询文档审核作业结果 本章节对查询文档审核作业结果AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryDocumentModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunQueryDocumentModerationJobRequest() request.job_id = "xxxx" response = client.run_query_document_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出查询文档审核作业结果。 {"job_id": "01693238400_cd7c8fd0a30b4c13b1fcaf9246c542c6", "status": "succeeded", "result": {"suggestion": "pass", "details": []}, "request_params": {"data": {"url": "http://xxxxx", "format": "pdf"}, "event_type": "default"}, "create_time": "2023-08-29T16:33:50.050Z", "update_time": "2023-08-29T16:33:50.050Z", "request_id": "e4eeb972aeb92f4269e8dfbb59ba7e3b"} 父主题: 文档审核
  • 创建文档内容审核作业 本章节对创建文档内容审核作业AK/SK方式使用SDK进行示例说明。 示例代码中可以使用DocumentCreateRequestData类的withUrl配置待审核的文档url,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunCreateDocumentModerationJobRequest() databody = DocumentCreateRequestData( url="http://xxx", format="pdf" ) request.body = DocumentCreateRequest( event_type="default", data=databody ) response = client.run_create_document_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出创建文档内容审核作业的结果。 {"request_id": "c083957284ce1f2c0b910115d8232ec6", "job_id": "01690387200_e3dfb78d9f20463f98aee25e6895203a"} 父主题: 文档审核
  • 查询文档审核作业结果 本章节对查询文档审核作业结果AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryDocumentModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.core.region.Region; import com.huaweicloud.sdk.moderation.v3.*; import com.huaweicloud.sdk.moderation.v3.model.*; public class RunQueryDocumentModerationJobSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); String iamEndpoint = "https://iam.cn-north-7.myhuaweicloud.com"; String endpoint = "https://moderation.cn-north-7.myhuaweicloud.com"; ICredential auth = new BasicCredentials() .withIamEndpoint(iamEndpoint) .withAk(ak) .withSk(sk); ModerationClient client = ModerationClient.newBuilder() .withCredential(auth) .withRegion(new Region("cn-north-7", endpoint)) .build(); RunQueryDocumentModerationJobRequest request = new RunQueryDocumentModerationJobRequest(); request.withJobId("xxxx"); try { RunQueryDocumentModerationJobResponse response = client.runQueryDocumentModerationJob(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 控制台输出查询文档审核作业结果。 class RunQueryDocumentModerationJobResponse { jobId: 01693238400_90b2f15d730f43958a74b93619f3ab78 status: succeeded result: class DocumentQueryResponseResult { suggestion: pass details: [] } requestParams: class DocumentQueryResponseRequestParams { data: class DocumentQueryResponseRequestParamsData { url: http://www.baidu.com format: pdf frameInterval: null } eventType: default imageCategories: null textCategories: null videoImageCategories: null audioCategories: null callback: null } createTime: 2023-08-29T15:08:12.012Z updateTime: 2023-08-29T15:08:13.013Z requestId: 33ca3825b6525bdc8cd7ee2502028692 } 父主题: 文档审核
  • 创建文档内容审核作业 本章节对创建文档内容审核作业AK/SK方式使用SDK进行示例说明。 示例代码中可以使用DocumentCreateRequestData类的withUrl配置待审核的文档url,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.core.region.Region; import com.huaweicloud.sdk.moderation.v3.*; import com.huaweicloud.sdk.moderation.v3.model.*; public class RunCreateDocumentModerationJobSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ModerationClient client = ModerationClient.newBuilder() .withCredential(auth) .withRegion(ModerationRegion.valueOf("xxx")) //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build(); RunCreateDocumentModerationJobRequest request = new RunCreateDocumentModerationJobRequest(); DocumentCreateRequest body = new DocumentCreateRequest(); DocumentCreateRequestData databody = new DocumentCreateRequestData(); databody.withUrl("http://xxx") .withFormat("pdf"); body.withEventType("default"); body.withData(databody); request.withBody(body); try { RunCreateDocumentModerationJobResponse response = client.runCreateDocumentModerationJob(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 控制台输出创建文档内容审核作业提交的结果。 class RunCreateDocumentModerationJobResponse { requestId: 86ad03c26917901d22e06d2f28ba2c7a jobId: 01690387200_1434ba6e1de44666877e748133b1d2e9 } 父主题: 文档审核
  • 关闭视频流内容审核作业 本章节对关闭视频流审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCloseVideoStreamModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunCloseVideoStreamModerationJobRequest{} request.JobId = "xxxxx" response, err := client.RunCloseVideoStreamModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出关闭视频流内容审核作业提交的结果。 RunCloseVideoStreamModerationJobResponse {"result": "success"} 父主题: 视频流审核
  • 创建视频流内容审核作业 本章节对创建视频流审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用VideoStreamCreateRequestData类的withUrls配置待审核的视频流url(仅支持url方式),配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunCreateVideoStreamModerationJobRequest{} var listImageCategoriesbody = []model.VideoStreamCreateRequestImageCategories{ model.GetVideoStreamCreateRequestImageCategoriesEnum().POLI TICS , } databody := &model.VideoStreamCreateRequestData{ Url: "http://xxx", } request.Body = &model.VideoStreamCreateRequest{ Callback: "http://xxxxxx", ImageCategories: listImageCategoriesbody, EventType: model.GetVideoStreamCreateRequestEventTypeEnum().DEFAULT, Data: databody, } response, err := client.RunCreateVideoStreamModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出创建视频流内容审核作业的结果。 RunCreateVideoStreamModerationJobResponse {"request_id": "fa520dddb6b54af51c8d1e6d19898656", "job_id": "01690387200_09ad14f155bb47e9bf2718ace57c73ed"} 父主题: 视频流审核
  • 关闭音频流内容审核作业 本章节对关闭音频流审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCloseAudioStreamModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunCloseAudioStreamModerationJobRequest{} request.JobId = "xxxxx" response, err := client.RunCloseAudioStreamModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出关闭音频流内容审核作业提交的结果。 RunCloseAudioStreamModerationJobResponse {"result": "success"} 父主题: 音频流审核
  • 创建音频流内容审核作业 本章节对创建音频流审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用AudioStreamCreateRequestData类的withUrls配置待审核的音频流url(仅支持url方式),配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunCreateAudioStreamModerationJobRequest{} var listCategoriesbody = []string{ "ad", } databody := &model.AudioStreamCreateRequestData{ Url: "http://xxx", } request.Body = &model.AudioStreamCreateRequest{ Callback: "http://xxxxxx", Categories: listCategoriesbody, EventType: "default", Data: databody, } response, err := client.RunCreateAudioStreamModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出创建音频流内容审核作业的结果。 RunCreateAudioStreamModerationJobResponse {"request_id": "303fbd70c9813a2476bad125fa436f00", "job_id": "11690387200_ffa1f5bb9a58451b86816gdfc654610e"} 父主题: 音频流审核
  • 关闭视频流内容审核作业 本章节对关闭视频流审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCloseVideoStreamModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunCloseVideoStreamModerationJobRequest() request.job_id = "xxxxx" response = client.run_close_video_stream_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出关闭视频流内容审核作业提交的结果。 { "result": "success" } 父主题: 视频流审核
  • 创建视频流内容审核作业 本章节对创建视频流审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用VideoStreamCreateRequestData类的withUrls配置待审核的视频流url(仅支持url方式),配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunCreateVideoStreamModerationJobRequest() listImageCategoriesbody = [ "politics" ] databody = VideoStreamCreateRequestData( url="http://xxx" ) request.body = VideoStreamCreateRequest( param_callback="http://xxxxxx", image_categories=listImageCategoriesbody, event_type="default", data=databody ) response = client.run_create_video_stream_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出创建视频流内容审核作业的结果。 { "request_id": "fa520dddb6b54af51c8d1e6d19898656", "job_id": "01690387200_09ad14f155bb47e9bf2718ace57c73ed" } 父主题: 视频流审核
  • 关闭音频流内容审核作业 本章节对关闭音频流审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCloseAudioStreamModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunCloseAudioStreamModerationJobRequest() request.job_id = "xxxxx" response = client.run_close_audio_stream_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出关闭音频流内容审核作业提交的结果。 { "result": "success" } 父主题: 音频流审核
  • 创建音频流内容审核作业 本章节对创建音频流审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用AudioStreamCreateRequestData类的withUrls配置待审核的音频流url(仅支持url方式),配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunCreateAudioStreamModerationJobRequest() listCategoriesbody = [ "ad" ] databody = AudioStreamCreateRequestData( url="http://xxx" ) request.body = AudioStreamCreateRequest( param_callback="http://xxxxxx", categories=listCategoriesbody, event_type="default", data=databody ) response = client.run_create_audio_stream_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出创建音频流内容审核作业的结果。 { "request_id": "303fbd70c9813a2476bad125fa436f00", "job_id": "11690387200_ffa1f5bb9a58451b86816gdfc654610e" } 父主题: 音频流审核
  • 关闭视频流内容审核作业 本章节对关闭视频流审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCloseVideoStreamModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.core.region.Region; import com.huaweicloud.sdk.moderation.v3.*; import com.huaweicloud.sdk.moderation.v3.model.*; public class RunCloseVideoStreamModerationJobSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ModerationClient client = ModerationClient.newBuilder() .withCredential(auth) .withRegion(ModerationRegion.valueOf("xxx")) //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build(); RunCloseVideoStreamModerationJobRequest request = new RunCloseVideoStreamModerationJobRequest(); request.withJobId("xxxxx"); try { RunCloseVideoStreamModerationJobResponse response = client.runCloseVideoStreamModerationJob(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 控制台输出关闭视频流内容审核作业的结果。 class RunCloseVideoStreamModerationJobResponse { result: success } 父主题: 视频流审核
  • 关闭音频流内容审核作业 本章节对关闭音频流审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCloseAudioStreamModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.core.region.Region; import com.huaweicloud.sdk.moderation.v3.*; import com.huaweicloud.sdk.moderation.v3.model.*; public class RunCloseAudioStreamModerationJobSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ModerationClient client = ModerationClient.newBuilder() .withCredential(auth) .withRegion(ModerationRegion.valueOf("xxx")) //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build(); RunCloseAudioStreamModerationJobRequest request = new RunCloseAudioStreamModerationJobRequest(); request.withJobId("xxxxxx"); try { RunCloseAudioStreamModerationJobResponse response = client.runCloseAudioStreamModerationJob(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 控制台输出关闭音频流内容审核作业的结果。 class RunCloseAudioStreamModerationJobResponse { result: success } 父主题: 音频流审核
  • 图像内容审核(V3) 本章节对图像内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用Url或Image配置图像信息(代表使用url或者图像的base64),示例中以url为例配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.CheckImageModerationRequest{} var listCategoriesbody = []string{ "porn", } urlImageDetectionReq:= "http://www.xxxx.xxxx" request.Body = &model.ImageDetectionReq{ Url: &urlImageDetectionReq, Categories: listCategoriesbody, EventType: "head_image", } response, err := client.CheckImageModeration(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 审核结果输出到控制台表示执行成功,图像内容审核结果输出到控制台。 CheckImageModerationResponse {"request_id": "69b424920668cb15e6d25eef879a023b", "result": {"suggestion": "block", "category": "image_text", "details": [{"suggestion": "block", "category": "image_text", "confidence": 1.0, "qr_location": {"top_left_x": 74, "top_left_y": 66, "bottom_right_x": 151, "bottom_right_y": 142}, "qr_content": "http://xxxxxx/xxxxx", "label": "qr_code"}, {"suggestion": "block", "category": "image_text", "confidence": 0.98779297, "label": "ad"}, {"suggestion": "block", "category": "image_text", "confidence": 1.0, "label": "qr_code"}], "ocr_text": "xxxxxxxxx"}} 父主题: 图像审核
  • 图像内容审核(V3) 本章节对图像内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以修改ImageDetectionReq的url或image方法配置图像信息(image和url参数二选一),示例中以url为例配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") projectId = "project_id" credentials = BasicCredentials(ak, sk, projectId) \ client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx")) \ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = CheckImageModerationRequest() listCategoriesbody = [ "porn" ] request.body = ImageDetectionReq( url="http://www.xxxx.xxxx", categories=listCategoriesbody, event_type="head_image" ) response = client.check_image_moderation(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,图像内容审核结果输出到控制台。 {"request_id": "69b424920668cb15e6d25eef879a023b", "result": {"suggestion": "block", "category": "image_text", "details": [{"suggestion": "block", "category": "image_text", "confidence": 1.0, "qr_location": {"top_left_x": 74, "top_left_y": 66, "bottom_right_x": 151, "bottom_right_y": 142}, "qr_content": "http://xxxxxx/xxxxx", "label": "qr_code"}, {"suggestion": "block", "category": "image_text", "confidence": 0.98779297, "label": "ad"}, {"suggestion": "block", "category": "image_text", "confidence": 1.0, "label": "qr_code"}], "ocr_text": "xxxxxxxxx"}} 父主题: 图像审核
  • Node.js环境SDK导入 使用SDK前,您需要安装“@huaweicloud/huaweicloud-sdk-core”和“@huaweicloud/huaweicloud-sdk-moderation”。 推荐您使用npm安装SDK,在命令行输入以下命令: npm install @huaweicloud/huaweicloud-sdk-core npm i @huaweicloud/huaweicloud-sdk-moderation 父主题: 使用SDK(Node.js)
  • 服务支持区域选择“华北-北京四”,这个对异地的有没有影响? 对异地是没有影响的,服务所支持的区域是指服务部署在该区域下的服务器,用户所在地区与服务部署区域不一致也是可以开通和使用本服务的。 如果请求输入的数据是OBS地址方式,就需要使用相同区域的内容审核服务。 例如:您的OBS请求数据在“华北-北京四”,只能调用“华北-北京四”区域下的内容审核服务,如果本服务不支持该区域则不能调用。 如果请求输入的数据是Base64图片或者公网URL,则不受区域影响。 例如:您的服务器在“华东-上海一”可以调用“华北-北京四”的内容审核服务接口。 内容审核服务暂不支持离线部署。 内容审核服务的支持区域请参考使用限制。 父主题: 服务开通
  • PHP环境SDK导入 PHP版本,内容审核服务推荐您使用 Composer 安装 SDK 。Composer 是 Php 的依赖管理工具,允许您在项目中声明依赖关系并安装这些依赖: // 安装 Composer curl -sS https://getcomposer.org/installer | php // 安装 PHP SDK composer require huaweicloud/huaweicloud-sdk-php 安装完毕后,你需要引入 Composer 的自动加载文件: require 'path/to/vendor/autoload.php'; 父主题: 使用SDK(PHP)
  • 查询视频内容审核作业 本章节对查询 视频审核 AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryVideoModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunQueryVideoModerationJobRequest{} request.JobId = "xxxx" //此处需要输入您的jobID response, err := client.RunQueryVideoModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出查询视频内容审核作业提交的结果,查询视频内容审核结果输出到控制台。 RunQueryVideoModerationJobResponse {"request_id":"xxxx","job_id":"xxx","status":"succeeded","request_params":{"data":{"url":"xxxx","frame_interval":5},"event_type":"default","image_categories":["porn","terrorism","image_text"],"audio_categories":["porn","ad","moan","abuse"],"callback":"xxx"},"create_time":"2022-07-30T08:57:11.011Z","update_time":"2022-07-30T08:57:14.014Z","result":{"suggestion":"block","image_detail":[{"suggestion":"block","category":"porn","ocr_text":"123","time":0,"detail":[{"confidence":0.676015138626099,"category":"porn","suggestion":"block","label":"pornography"},{"confidence":0.666015138626099,"category":"porn","suggestion":"review","label":"sexy_female"},{"confidence":0.666015138626099,"category":"xxx","suggestion":"block","label":"leader"},{"confidence":0.691423773765564,"category":"xxx","suggestion":"block","face_location":{"top_left_x":12,"top_left_y":13,"bottom_right_x":200,"bottom_right_y":240},"label":"leader"},{"confidence":0.691423773765564,"category":"porn","suggestion":"block","face_location":{"top_left_x":12,"top_left_y":13,"bottom_right_x":100,"bottom_right_y":2000},"label":"leader"},{"confidence":0.891423773765564,"category":"image_text","suggestion":"block","label":"qr_code"},{"confidence":0.891423773765564,"category":"image_text","suggestion":"block","label":"qr_code","qr_content":"xxxxxxxxx","qr_location":{"top_left_x":12,"top_left_y":13,"bottom_right_x":100,"bottom_right_y":2000}},{"confidence":0.891423773765564,"category":"image_text","suggestion":"block","label":"porn","segments":[{"segment":"xxx"},{"segment":"xx"}]}]}],"audio_detail":[{"suggestion":"block","label":"porn","audio_text":"xxxxx","end_time":10,"start_time":0,"detail":[{"confidence":0.999117187582349,"label":"porn","suggestion":"block","segments":[{"segment":"xxx"}]},{"confidence":0.885117187582349,"label":"porn","suggestion":"block"}]}]}} 父主题: 视频审核
  • 创建视频内容审核作业 本章节对创建视频审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用RunCreateVideoModerationJobRequest类的withUrls配置待审核的视频url(仅支持url方式),配置完成后运行即可。 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("xxx")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 WithCredential(auth). Build()) request := &model.RunCreateVideoModerationJobRequest{} var listAudioCategoriesbody = []model.VideoCreateRequestAudioCategories{ model.GetVideoCreateRequestAudioCategoriesEnum().PORN, } var listImageCategoriesbody = []model.VideoCreateRequestImageCategories{ model.GetVideoCreateRequestImageCategoriesEnum().PORN, } frameIntervalData:= float32(5.5) databody := &model.VideoCreateRequestData{ Url: "http://xxx.xx.xxxx", FrameInterval: &frameIntervalData, } callbackVideoCreateRequest:= "http://xxx.xx.xxxx" request.Body = &model.VideoCreateRequest{ Callback: &callbackVideoCreateRequest, AudioCategories: &listAudioCategoriesbody, ImageCategories: listImageCategoriesbody, EventType: model.GetVideoCreateRequestEventTypeEnum().DEFAULT, Data: databody, } response, err := client.RunCreateVideoModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出创建视频内容审核作业的结果,创建视频内容审核结果输出到控制台。 RunCreateVideoModerationJobResponse{"request_id":"dbbcb75d1a174bfa899a38be38fdd107", "job_id": "xxx"} 父主题: 视频审核
  • 查询视频内容审核作业 本章节对查询视频审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryVideoModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Moderation; using HuaweiCloud.SDK.Moderation.V3; using HuaweiCloud.SDK.Moderation.V3.Model; namespace RunQueryVideoModerationJobSolution { class Program { static void Main(string[] args) { //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string ak= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string sk= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ModerationClient.NewBuilder() .WithCredential(auth) .WithRegion(ModerationRegion.ValueOf("xxx")) //把xxx替换成服务所在的区域,例如北京四:cn-north-4 .WithHttpConfig(config) .Build(); var req = new RunQueryVideoModerationJobRequest { JobId = "xxxx" //此处需要输入您的jobID }; try { var resp = client.RunQueryVideoModerationJob(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody)); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 控制台输出查询视频内容审核作业提交的结果,查询视频内容审核结果输出到控制台。 200 { "request_id":"xxxx", "job_id":"xxx", "status":"succeeded", "request_params":{ "data":{ "url":"xxxx", "frame_interval":5 }, "event_type":"default", "image_categories":[ "porn", "terrorism", "image_text" ], "audio_categories":[ "porn", "ad", "moan", "abuse" ], "callback":"xxx" }, "create_time":"2022-07-30T08:57:11.011Z", "update_time":"2022-07-30T08:57:14.014Z", "result":{ "suggestion":"block", "image_detail":[ { "suggestion":"block", "category":"porn", "ocr_text":"123", "time":0, "detail":[ { "confidence":0.676015138626099, "category":"porn", "suggestion":"block", "label":"pornography" }, { "confidence":0.666015138626099, "category":"porn", "suggestion":"review", "label":"sexy_female" }, { "confidence":0.666015138626099, "category":"xxx", "suggestion":"block", "label":"leader" }, { "confidence":0.691423773765564, "category":"xxx", "suggestion":"block", "face_location":{ "top_left_x":12, "top_left_y":13, "bottom_right_x":200, "bottom_right_y":240 }, "label":"leader" }, { "confidence":0.691423773765564, "category":"porn", "suggestion":"block", "face_location":{ "top_left_x":12, "top_left_y":13, "bottom_right_x":100, "bottom_right_y":2000 }, "label":"leader" }, { "confidence":0.891423773765564, "category":"image_text", "suggestion":"block", "label":"qr_code" }, { "confidence":0.891423773765564, "category":"image_text", "suggestion":"block", "label":"qr_code", "qr_content":"xxxxxxxxx", "qr_location":{ "top_left_x":12, "top_left_y":13, "bottom_right_x":100, "bottom_right_y":2000 } }, { "confidence":0.891423773765564, "category":"image_text", "suggestion":"block", "label":"porn", "segments":[ { "segment":"xxx" }, { "segment":"xx" } ] } ] } ], "audio_detail":[ { "suggestion":"block", "label":"porn", "audio_text":"xxxxx", "end_time":10, "start_time":0, "detail":[ { "confidence":0.999117187582349, "label":"porn", "suggestion":"block", "segments":[ { "segment":"xxx" } ] }, { "confidence":0.885117187582349, "label":"porn", "suggestion":"block" } ] } ] } } 父主题: 视频审核
  • 查询视频内容审核作业 本章节对查询视频审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryVideoModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx")) \ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunQueryVideoModerationJobRequest() request.job_id = "xxx" //此处需要输入您的jobID response = client.run_query_video_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出查询视频内容审核作业的结果,查询视频内容审核结果输出到控制台。 {"request_id":"xxxx","job_id":"xxx","status":"succeeded","request_params":{"data":{"url":"xxxx","frame_interval":5},"event_type":"default","image_categories":["porn","terrorism","image_text"],"audio_categories":["porn","ad","moan","abuse"],"callback":"xxx"},"create_time":"2022-07-30T08:57:11.011Z","update_time":"2022-07-30T08:57:14.014Z","result":{"suggestion":"block","image_detail":[{"suggestion":"block","category":"porn","ocr_text":"123","time":0,"detail":[{"confidence":0.676015138626099,"category":"porn","suggestion":"block","label":"pornography"},{"confidence":0.666015138626099,"category":"porn","suggestion":"review","label":"sexy_female"},{"confidence":0.666015138626099,"category":"xxx","suggestion":"block","label":"leader"},{"confidence":0.691423773765564,"category":"xxx","suggestion":"block","face_location":{"top_left_x":12,"top_left_y":13,"bottom_right_x":200,"bottom_right_y":240},"label":"leader"},{"confidence":0.691423773765564,"category":"porn","suggestion":"block","face_location":{"top_left_x":12,"top_left_y":13,"bottom_right_x":100,"bottom_right_y":2000},"label":"leader"},{"confidence":0.891423773765564,"category":"image_text","suggestion":"block","label":"qr_code"},{"confidence":0.891423773765564,"category":"image_text","suggestion":"block","label":"qr_code","qr_content":"xxxxxxxxx","qr_location":{"top_left_x":12,"top_left_y":13,"bottom_right_x":100,"bottom_right_y":2000}},{"confidence":0.891423773765564,"category":"image_text","suggestion":"block","label":"porn","segments":[{"segment":"xxx"},{"segment":"xx"}]}]}],"audio_detail":[{"suggestion":"block","label":"porn","audio_text":"xxxxx","end_time":10,"start_time":0,"detail":[{"confidence":0.999117187582349,"label":"porn","suggestion":"block","segments":[{"segment":"xxx"}]},{"confidence":0.885117187582349,"label":"porn","suggestion":"block"}]}]}} 父主题: 视频审核
  • 调用服务时错误码显示“ModelArts.4204”怎么处理? 调用接口出错后,返回的消息体中具体的错误代码及错误信息为: { "error_code":"ModelArts.4204", "error_msg":"Request api error! The API is not subscribed." } 表明您还未订阅该区域下的内容审核服务,请您开通后再使用该服务,详细步骤请参考开通服务。 注意核对您开通本服务的区域,如开通“华北-北京四”下的 文本内容审核 功能,则您在“华东-上海一”调用该接口就会出现该错误码。 出现其它错误码及错误信息说明请参考表-错误码说明,在调用方找不到错误原因时,可以联系华为云客服,并提供错误码,以便尽快帮您解决问题。 父主题: 错误码问题
  • 创建视频内容审核作业 本章节对创建视频审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用RunCreateVideoModerationJobRequest类的withUrls配置待审核的视频url(仅支持url方式),配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx")) \ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunCreateVideoModerationJobRequest() listAudioCategoriesbody = [ "porn" ] listImageCategoriesbody = [ "porn" ] databody = VideoCreateRequestData( url="http://xxx.xx.xxxx", frame_interval=5.5 ) request.body = VideoCreateRequest( callback="http://xxx.xx.xxxx", audio_categories=listAudioCategoriesbody, image_categories=listImageCategoriesbody, event_type="default", data=databody ) response = client.run_create_video_moderation_job(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出创建视频内容审核作业的结果,创建视频内容审核结果输出到控制台。 {"request_id": "dbbcb75d1a174bfa899a38be38fdd107", "job_id": "xxx"} 父主题: 视频审核
  • 查询视频内容审核作业 本章节对查询视频审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryVideoModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.moderation.v3.region.ModerationRegion; import com.huaweicloud.sdk.moderation.v3.*; import com.huaweicloud.sdk.moderation.v3.model.*; public class RunQueryVideoModerationJobSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ModerationClient client = ModerationClient.newBuilder() .withCredential(auth) .withRegion(ModerationRegion.valueOf("xxx")) //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build(); RunQueryVideoModerationJobRequest request = new RunQueryVideoModerationJobRequest(); request.withJobId("jobId"); try { RunQueryVideoModerationJobResponse response = client.runQueryVideoModerationJob(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 控制台输出查询视频内容审核作业的结果,查询视频内容审核结果输出到控制台。 父主题: 视频审核
  • 文本内容审核(V3) 本章节对文本内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以修改TextDetectionDataReq的Text 配置待检测的文本信息,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Moderation; using HuaweiCloud.SDK.Moderation.V3; using HuaweiCloud.SDK.Moderation.V3.Model; namespace RunTextModerationSolution { class Program { static void Main(string[] args) { //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string ak= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string sk= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ModerationClient.NewBuilder() .WithCredential(auth) .WithRegion(ModerationRegion.ValueOf("xxx")) //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .WithHttpConfig(config) .Build(); var req = new RunTextModerationRequest { }; TextDetectionDataReq databody = new TextDetectionDataReq() { Text = "test" }; req.Body = new TextDetectionReq() { Data = databody, EventType = "comment" }; try { var resp = client.RunTextModeration(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 控制台输出200即表示程序执行成功,文本内容审核结果输出到控制台。 200 { "request_id":"d81702cfd3599e103030c3d52d6f955f", "result":{ "suggestion":"pass", "label":"normal", "details":[] } } 父主题: 文本审核
  • 检查原因 请确认当前账号是否欠费。如果欠费,请给账号充值。操作指导请参见华为云账户充值。 您在创建和调用OBS桶时,需保证您的OBS桶与内容审核在同一个区域,不支持跨区域使用。例如同为“华北-北京一”区域,具体请参见内容审核地区和终端节点。 根据API调用返回结果或者错误码查找原因,具体请参见内容审核错误码。 检查访问密钥AK/SK是否获取成功,获取方式请参见获取AK/SK。 检查Token是否填写正确或者已过期。 检查API调用方法是否正确,具体操作请参见《内容审核API参考》。
  • 文本内容审核(v3) 本章节对文本内容审核AK/SK方式使用SDK进行示例说明。 示例代码中修改TextDetectionDataReq的text值配置待检测的文本信息,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmoderation.v3.region.moderation_region import ModerationRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v3 import * import os if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ModerationClient.new_builder() \ .with_credentials(credentials) \ .with_region(ModerationRegion.value_of("xxx"))\ //把xxx替换成服务所在的区域,例如北京四:cn-north-4。 .build() try: request = RunTextModerationRequest() databody = TextDetectionDataReq( text="test" ) request.body = TextDetectionReq( data=databody, event_type="comment" ) response = client.run_text_moderation(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,文本内容审核结果输出到控制台。 {"request_id": "d81702cfd3599e103030c3d52d6f955f", "result": {"suggestion": "pass", "label": "normal", "details": []}} 父主题: 文本审核
共100000条