华为云用户手册

  • 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"}]}]}} 父主题: 视频审核
  • 创建视频内容审核作业 本章节对创建视频审核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 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/core/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.RunTextModerationRequest{} databody := &model.TextDetectionDataReq{ Text: "text", } request.Body = &model.TextDetectionReq{ Data: databody, EventType: "comment", } response, err := client.RunTextModeration(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 审核结果输出到控制台表示执行成功,文本内容审核结果输出到控制台。 RunTextModerationResponse {"request_id": "d81702cfd3599e103030c3d52d6f955f", "result": {"suggestion": "pass", "label": "normal", "details": []}} 父主题: 文本审核
  • 文本内容审核(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":[] } } 父主题: 文本审核
  • 文本内容审核(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": []}} 父主题: 文本审核
  • 文本内容审核(V3) 本章节对文本内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用TextDetectionDataReq类的withText方法配置待检测的文本信息,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 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 RunTextModerationSolution { 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(); RunTextModerationRequest request = new RunTextModerationRequest(); TextDetectionReq body = new TextDetectionReq(); TextDetectionDataReq databody = new TextDetectionDataReq(); databody.withText("test"); body.withData(databody); body.withEventType("comment"); request.withBody(body); try { RunTextModerationResponse response = client.runTextModeration(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()); } } } 控制台输出200即表示程序执行成功,文本内容审核结果输出到控制台。 class RunTextModerationResponse { requestId: 308b6ad2740e51de73597da9fdc94ee1 result: class TextDetectionResult { suggestion: pass label: normal details: [] } } 父主题: 文本审核
  • 查询音频内容审核作业 本章节对查询音频审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryAudioModerationJobRequest类的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.RunQueryAudioModerationJobRequest{} request.JobId = "" response, err := client.RunQueryAudioModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出查询音频内容审核的结果,查询音频内容审核结果输出到控制台。 RunQueryAudioModerationJobResponse {"job_id": "xxx", "status": "running", "request_params": {"event_type": "default", "data": {"url": "https://***.wav"}, "categories": ["porn"]}, "create_time": "2022-08-29T11:57:14.014Z", "update_time": "2022-08-29T11:57:14.014Z", "request_id": "c16c9fdeb3c1b838d9cec08ada4b6b96"} 父主题: 音频审核
  • 创建音频内容审核作业 本章节对创建音频审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用RunCreateAudioModerationJobRequest类的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.RunCreateAudioModerationJobRequest{} var listCategoriesbody = []model.AudioCreateRequestCategories{ model.GetAudioCreateRequestCategoriesEnum().PORN, } databody := &model.AudioInputBody{ Url: "", } request.Body = &model.AudioCreateRequest{ Categories: &listCategoriesbody, EventType: model.GetAudioCreateRequestEventTypeEnum().DEFAULT, Data: databody, } response, err := client.RunCreateAudioModerationJob(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 控制台输出创建音频内容审核提交的结果,创建音频内容审核结果输出到控制台。 RunCreateAudioModerationJobResponse{"request_id":"0b111ce94ec3d563a40d4e51a096d996", "job_id": "xxx"} 父主题: 音频审核
  • 查询任务 本章节对图像内容审核异步批量-查询任务AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCheckResultRequest的JobId配置审核任务的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/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/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.RunCheckResultRequest{} request.JobId = "70e952b5-5fa3-4d18-9ce4-75bba7226d7c" response, err := client.RunCheckResult(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 审核结果输出到控制台表示执行成功,异步批量查询任务的结果输出到控制台。 RunCheckResultResponse {"result":{"job_id":"xxx","status":"finish","create_time":"2021-08-05T03:44:37Z","update_time":"2021-08-05T03:44:37Z","items":[{"url":"https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg","suggestion":"pass","detail":{"porn":[{"confidence":0.9883,"label":"normal"},{"confidence":0.0039,"label":"porn"},{"confidence":0.0078,"label":"sexy"}],"terrorism":[{"confidence":0.0002,"label":"terrorist"},{"confidence":0.0002,"label":"fascist"},{"confidence":0.0001,"label":"cult"},{"confidence":0.0001,"label":"kidnap"},{"confidence":0.0006,"label":"riot"},{"confidence":0.0001,"label":"parade"},{"confidence":0.0002,"label":"corpse"},{"confidence":0.0001,"label":"bloody"},{"confidence":0.0001,"label":"knife"},{"confidence":0.0001,"label":"gun"},{"confidence":0.0002,"label":"military_weapon"},{"confidence":0,"label":"special_characters"},{"confidence":0.9994,"label":"normal"}]},"category_suggestions":{"porn":"pass","terrorism":"pass"}}]}} Process exiting with code: 0 父主题: 内容审核-图像 (异步批量)(V2)
  • 提交任务 本章节对图像内容审核(异步批量)-提交任务AK/SK方式使用SDK进行示例说明。 示例代码中可以修改TaskSumbitReq的Urls配置待审核的图像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/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/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.RunTaskSumbitRequest{} var listCategoriesbody = []model.TaskSumbitReqCategories{ model.GetTaskSumbitReqCategoriesEnum().PORN, model.GetTaskSumbitReqCategoriesEnum().TERRORISM, } var listUrlsbody = []string{ "https://XXX.jpg", //此处替换为公网可以访问的图片地址 } request.Body = &model.TaskSumbitReq{ Categories: &listCategoriesbody, Urls: listUrlsbody, } response, err := client.RunTaskSumbit(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) }} 提交任务结果输出到控制台表示执行成功,异步批量任务提交的结果输出到控制台。 RunTaskSumbitResponse {"result":{"job_id":"xxx"}} Process exiting with code: 0 父主题: 内容审核-图像(异步批量)(V2)
  • 查询音频内容审核作业 本章节对查询音频内容审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryAudioModerationJobRequest类的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 RunQueryAudioModerationJobSolution { 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 RunQueryAudioModerationJobRequest { JobId = "xxx" //此处需要输入您的jobID }; try { var resp = client.RunQueryAudioModerationJob(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即表示程序执行成功,查询音频内容审核结果输出到控制台。 200 { "job_id":"xxx", "status":"succeeded", "result":{ "suggestion":"block", "details":[ { "start_time":0, "suggestion":"block", "end_time":10, "label":"porn", "audio_text":"xxxx", "segments":[ { "segment":"xxx" }, { "segment":"xxx" }, { "segment":"xxx" } ] }, { "start_time":30, "suggestion":"block", "end_time":40, "label":"porn", "audio_text":"xxx", "segments":[ { "segment":"xx" } ] } ], "audio_text":"xxxxxx" }, "request_params":{ "event_type":"default", "data":{ "url":"https://xxxx.wav" }, "callback":"http://xxx", "categories":[ "porn", "ad" ] }, "create_time":"2022-06-20 11:05:29", "update_time":"2022-06-20 11:07:08", "request_id":"2419446b1fe14203f64e4018d12db3dd" } 父主题: 音频审核
  • 查询音频内容审核作业 本章节对查询音频审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryAudioModerationJobRequest类的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 = RunQueryAudioModerationJobRequest() request.job_id = "xxx" //此处需要输入您的jobID response = client.run_query_audio_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":"xxxx","status":"succeeded","result":{"suggestion":"block","details":[{"start_time":0,"suggestion":"block","end_time":10,"label":"porn","audio_text":"xxxx","segments":[{"segment":"xxx"},{"segment":"xxx"},{"segment":"xxx"}]},{"start_time":30,"suggestion":"block","end_time":40,"label":"porn","audio_text":"xxx","segments":[{"segment":"xx"}]}],"audio_text":"xxxxxx"},"request_params":{"event_type":"default","data":{"url":"https://xxxx.wav"},"callback":"http://xxx","categories":["porn","ad"]},"create_time":"2022-06-20 11:05:29","update_time":"2022-06-20 11:07:08","request_id":"2419446b1fe14203f64e4018d12db3dd"} 父主题: 音频审核
  • 创建音频内容审核作业 本章节对创建音频审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用RunCreateAudioModerationJobRequest类的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 = __import__('os').getenv("CLOUD_SDK_AK") sk = __import__('os').getenv("CLOUD_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 = RunCreateAudioModerationJobRequest() listCategoriesbody = [ "ad" ] databody = AudioInputBody( url="http://xxx.wav" ) request.body = AudioCreateRequest( categories=listCategoriesbody, event_type="default", data=databody ) response = client.run_create_audio_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": "0b111ce94ec3dXXX4e51a096d996", "job_id": "xxx"} 父主题: 音频审核
  • 查询音频内容审核作业 本章节对查询音频审核AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunQueryAudioModerationJobRequest类的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 RunQueryAudioModerationJobSolution { 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(); RunQueryAudioModerationJobRequest request = new RunQueryAudioModerationJobRequest(); request.withJobId("xxx"); try { RunQueryAudioModerationJobResponse response = client.runQueryAudioModerationJob(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()); } } } 控制台输出查询音频内容审核作业的结果,查询音频内容审核结果输出到控制台。 class RunQueryAudioModerationJobResponse { jobId: 01661702400_cd06d61c16a14565995fcbfb04877bd3 status: running result: null requestParams: class AudioModerationResultRequestParams { eventType: default data: class AudioModerationResultRequestParamsData { url: https://****.wav } callback: null categories: [porn] } createTime: 2022-08-29T11:57:14.014Z updateTime: 2022-08-29T11:57:14.014Z requestId: 57ea754a1fdec2d13e4e8ffbff6a458d } 父主题: 音频审核
  • 查询任务 本章节对图像内容审核异步批量-查询任务AK/SK方式使用SDK进行示例说明。 示例代码中需要修改RunCheckResultRequest的JobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Moderation; using HuaweiCloud.SDK.Moderation.V2; using HuaweiCloud.SDK.Moderation.V2.Model; namespace RunCheckResultSolution { 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 RunCheckResultRequest { JobId = "2991572e-f503-11eb-a32d-88bd0dde8061" }; try { var resp = client.RunCheckResult(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即表示程序执行成功,异步批量查询任务的结果输出到控制台。 200 {'result': {'create_time': '2021-08-04T08:30:41Z', 'items': [{'category_suggestions': { 'porn': 'pass', 'terrorism': 'pass'}, 'detail': {'ad': None, 'porn': [{'confidence': 0.9883, 'label': 'normal'}, {'confidence': 0.0039, 'label': 'porn'}, {'confidence': 0.0078, 'label': 'sexy'}], 'terrorism': [{'confidence': 0.0002, 'label': 'terrorist'}, {'confidence': 0.0002, 'label': 'fascist'}, {'confidence': 0.0001, 'label': 'cult'}, {'confidence': 0.0002, 'label': 'negative_politics'}, {'confidence': 0.0001, 'label': 'kidnap'}, {'confidence': 0.0006, 'label': 'riot'}, {'confidence': 0.0001, 'label': 'parade'}, {'confidence': 0.0002, 'label': 'corpse'}, {'confidence': 0.0001, 'label': 'bloody'}, {'confidence': 0.0001, 'label': 'knife'}, {'confidence': 0.0001, 'label': 'gun'}, {'confidence': 0.0002, 'label': 'military_weapon'}, {'confidence': 0.0, 'label': 'special_characters'}, {'confidence': 0.9994, 'label': 'normal'}]}, 'suggestion': 'pass', 'url': 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'}], 'job_id': 'xxx', 'status': 'finish', 'update_time': '2021-08-04T08:30:41Z'}} 父主题: 内容审核-图像(异步批量)(V2)
  • 查询任务 本章节对图像内容审核异步批量-查询任务AK/SK方式使用SDK进行示例说明。 示例代码中修改RunCheckResultRequest的job_id 配置审核任务的id,配置完成后运行即可。服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v2.region.moderation_region import ModerationRegion from huaweicloudsdkmoderation.v2 import * from huaweicloudsdkmoderation.v2 import ModerationClient,RunCheckResultRequest 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 = RunCheckResultRequest() request.job_id = "xxx" //此处需要输入您的jobID response = client.run_check_result(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,异步批量查询任务的结果输出到控制台。 200 {'result': {'create_time': '2021-08-04T08:30:41Z', 'items': [{'category_suggestions': { 'porn': 'pass', 'terrorism': 'pass'}, 'detail': {'ad': None, 'porn': [{'confidence': 0.9883, 'label': 'normal'}, {'confidence': 0.0039, 'label': 'porn'}, {'confidence': 0.0078, 'label': 'sexy'}], 'terrorism': [{'confidence': 0.0002, 'label': 'terrorist'}, {'confidence': 0.0002, 'label': 'fascist'}, {'confidence': 0.0001, 'label': 'cult'}, {'confidence': 0.0001, 'label': 'kidnap'}, {'confidence': 0.0006, 'label': 'riot'}, {'confidence': 0.0001, 'label': 'parade'}, {'confidence': 0.0002, 'label': 'corpse'}, {'confidence': 0.0001, 'label': 'bloody'}, {'confidence': 0.0001, 'label': 'knife'}, {'confidence': 0.0001, 'label': 'gun'}, {'confidence': 0.0002, 'label': 'military_weapon'}, {'confidence': 0.0, 'label': 'special_characters'}, {'confidence': 0.9994, 'label': 'normal'}]}, 'suggestion': 'pass', 'url': 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'}], 'job_id': 'xxx', 'status': 'finish', 'update_time': '2021-08-04T08:30:41Z'}} Process finished with exit code 0 父主题: 图像内容审核(异步批量)(V2)
  • 提交任务 本章节对图像内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以修改TaskSumbitReq的urls配置待审核的图像url(仅支持url方式),配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v2.region.moderation_region import ModerationRegion from huaweicloudsdkmoderation.v2 import * from huaweicloudsdkmoderation.v2 import ModerationClient,RunTaskSumbitRequest,TaskSumbitReq 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 = RunTaskSumbitRequest() listTaskSumbitReqCategoriesbody = [ "porn", "terrorism" ] listTaskSumbitReqUrlsbody = [ "https://XXX.jpg" //此处替换为公网可以访问的图片地址 ] request.body = TaskSumbitReq( categories=listTaskSumbitReqCategoriesbody, urls=listTaskSumbitReqUrlsbody ) response = client.run_task_sumbit(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,异步批量任务提交的结果输出到控制台。 200 {'result': {'job_id': 'xxx'}} Process finished with exit code 0 父主题: 图像内容审核(异步批量)(V2)
  • 图像内容审核(批量)(V2) 本章节对图像内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以修改ImageBatchModerationReq的urls配置待审核的图像url(仅支持url方式),配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v2.region.moderation_region import ModerationRegion from huaweicloudsdkmoderation.v2 import ModerationClient,RunImageBatchModerationRequest,ImageBatchModerationReq 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 = RunImageBatchModerationRequest() listImageBatchModerationReqCategoriesbody = [ "terrorism", "porn", "ad" ] listImageBatchModerationReqUrlsbody = [ "https://XXX.jpg" //此处替换为公网可以访问的图片地址 ] request.body = ImageBatchModerationReq( threshold=0, categories=listImageBatchModerationReqCategoriesbody, urls=listImageBatchModerationReqUrlsbody ) response = client.run_image_batch_moderation(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,图像内容审核批量任务提交的结果输出到控制台。 200 {'result': [{'category_suggestions': {'ad': 'pass', 'porn': 'pass', 'terrorism': 'pass'}, 'detail': { 'ad': [{'confidence': 0.0, 'label': 'ad'}, {'confidence': 1.0, 'label': 'normal'}], 'porn': [{'confidence': 0.9883, 'label': 'normal'}, {'confidence': 0.0039, 'label': 'porn'}, {'confidence': 0.0078, 'label': 'sexy'}], 'terrorism': [{'confidence': 0.0002, 'label': 'terrorist'}, {'confidence': 0.0002, 'label': 'fascist'}, {'confidence': 0.0001, 'label': 'cult'}, {'confidence': 0.0001, 'label': 'kidnap'}, {'confidence': 0.0006, 'label': 'riot'}, {'confidence': 0.0001, 'label': 'parade'}, {'confidence': 0.0002, 'label': 'corpse'}, {'confidence': 0.0001, 'label': 'bloody'}, {'confidence': 0.0001, 'label': 'knife'}, {'confidence': 0.0001, 'label': 'gun'}, {'confidence': 0.0002, 'label': 'military_weapon'}, {'confidence': 0.0, 'label': 'special_characters'}, {'confidence': 0.9994, 'label': 'normal'}]}, 'suggestion': 'pass', 'url': 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'}]} Process finished with exit code 0 父主题: 图像审核
  • 图像内容审核(V2) 本章节对图像内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以修改ImageDetectionReq的url或image方法配置图像信息(image和url参数二选一),示例中以url为例配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v2.region.moderation_region import ModerationRegion from huaweicloudsdkmoderation.v2 import ModerationClient,RunImageModerationRequest,ImageDetectionReq 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 = RunImageModerationRequest() listImageDetectionReqCategoriesbody = [ "terrorism", "porn", "ad" ] request.body = ImageDetectionReq( threshold=0, categories=listImageDetectionReqCategoriesbody, moderation_rule="default", url="https://XXX.jpg" //此处替换为公网可以访问的图片地址 ) response = client.run_image_moderation(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,图像内容审核结果输出到控制台。 200 {"result": {"detail": { "porn": [{"confidence": 0.9883, "label": "normal"}, {"confidence": 0.0039, "label": "porn"}, {"confidence": 0.0078, "label": "sexy"}], "terrorism": [{"confidence": 0.0002, "label": "terrorist"}, {"confidence": 0.0002, "label": "fascist"}, {"confidence": 0.0001, "label": "cult"}, {"confidence": 0.0002}, {"confidence": 0.0001, "label": "kidnap"}, {"confidence": 0.0006, "label": "riot"}, {"confidence": 0.0001, "label": "parade"}, {"confidence": 0.0002, "label": "corpse"}, {"confidence": 0.0001, "label": "bloody"}, {"confidence": 0.0001, "label": "knife"}, {"confidence": 0.0001, "label": "gun"}, {"confidence": 0.0002, "label": "military_weapon"}, {"confidence": 0.0, "label": "special_characters"}, {"confidence": 0.9994, "label": "normal"}], "ad": [{"confidence": 0.0, "label": "ad"}, {"confidence": 1.0, "label": "normal"}]}, "suggestion": "pass", "category_suggestions": { "ad": "pass", "terrorism": "pass", "porn": "pass"}}} Process finished with exit code 0 父主题: 图像审核
  • 文本内容审核(v2) 本章节对文本内容审核AK/SK方式使用SDK进行示例说明。 示例代码中修改TextDetectionItemsReq的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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmoderation.v2.region.moderation_region import ModerationRegion from huaweicloudsdkmoderation.v2 import ModerationClient,RunTextModerationRequest,TextDetectionItemsReq,TextDetectionReq 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() listTextDetectionItemsReqItemsbody = [ TextDetectionItemsReq( text="text", //此处输入待检测文本 type="content" ) ] listTextDetectionReqCategoriesbody = [ "porn", "ad", "abuse", "contraband", "flood" ] request.body = TextDetectionReq( items=listTextDetectionItemsReqItemsbody, categories=listTextDetectionReqCategoriesbody ) response = client.run_text_moderation(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 控制台输出200即表示程序执行成功,文本内容审核结果输出到控制台。 200 {"result": {"suggestion": "block", "detail": {"contraband": ["亚砷酸钾"], "porn": ["luo聊"]}}}} 父主题: 文本审核
  • 查询任务 本章节对图像内容审核异步批量-查询任务AK/SK方式使用SDK进行示例说明。 示例代码中需要配置使用RunCheckResultRequest类的withJobId配置审核任务的id,配置完成后运行即可。 服务所在的应用区域和终端节点,详情请查看 地区和终端节点 。 package com.huaweicloud.sdk.test; import com.alibaba.fastjson.JSON; 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.v2.ModerationClient; import com.huaweicloud.sdk.moderation.v2.region.ModerationRegion; import com.huaweicloud.sdk.moderation.v2.model.RunCheckResultRequest; import com.huaweicloud.sdk.moderation.v2.model.RunCheckResultResponse; public class RunCheckResultSolution { 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(); RunCheckResultRequest request = new RunCheckResultRequest(); request.withJobId("7f6a5881-7774-40cf-903b-4548914b55a3"); try { RunCheckResultResponse response = client.runCheckResult(request); System.out.println(response.getHttpStatusCode()); System.out.println(JSON.toJSONString(response)); } 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()); } } } 控制台输出200即表示程序执行成功,异步批量查询任务的结果输出到控制台。 200 {"httpStatusCode":200,"result":{"createTime":"2021-08-13T03:46:30Z","items":[{"categorySuggestions":{ "terrorism":"pass","porn":"pass"},"detail":{"porn":[{"confidence":0.9883,"label":"normal"},{"confidence":0.0039,"label":"porn"},{"confidence":0.0078,"label":"sexy"}],"terrorism":[{"confidence":2.0E-4,"label":"terrorist"},{"confidence":2.0E-4,"label":"fascist"},{"confidence":1.0E-4,"label":"cult"},{"confidence":2.0E-4},{"confidence":1.0E-4},{"confidence":1.0E-4,"label":"kidnap"},{"confidence":6.0E-4,"label":"riot"},{"confidence":1.0E-4,"label":"parade"},{"confidence":2.0E-4,"label":"corpse"},{"confidence":1.0E-4,"label":"bloody"},{"confidence":1.0E-4,"label":"knife"},{"confidence":1.0E-4,"label":"gun"},{"confidence":2.0E-4,"label":"military_weapon"},{"confidence":0.0,"label":"special_characters"},{"confidence":0.9994,"label":"normal"}]},"suggestion":"pass","url":"https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg"}],"jobId":"7f6a5881-7774-40cf-903b-4548914b55a3","status":"finish","updateTime":"2021-08-13T03:46:30Z"}} Process finished with exit code 0 父主题: 图像内容审核(异步批量)(V2)
  • 图像内容审核(批量)(V2) 本章节对图像内容审核(批量)AK/SK方式使用SDK进行示例说明。 示例代码中修改ImageBatchModerationReq的Urls配置待审核的图像url(仅支持url方式),配置完成后运行即可。 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/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.RunImageBatchModerationRequest{} var listCategoriesbody = []model.ImageBatchModerationReqCategories{ model.GetImageBatchModerationReqCategoriesEnum().TERRORISM, model.GetImageBatchModerationReqCategoriesEnum().PORN, model.GetImageBatchModerationReqCategoriesEnum().AD, } var listUrlsbody = []string{ "https://XXX.jpg", //此处替换为公网可以访问的图片地址 } thresholdImageBatchModerationReq:= float64(0) request.Body = &model.ImageBatchModerationReq{ Threshold: &thresholdImageBatchModerationReq, Categories: &listCategoriesbody, Urls: listUrlsbody, } response, err := client.RunImageBatchModeration(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) }} 审核结果输出到控制台表示执行成功,图像内容审核批量任务提交的结果输出到控制台。 RunImageBatchModerationResponse {"result":[{"url":"https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg","suggestion":"pass","detail":{"porn":[{"confidence":0.9883,"label":"normal"},{"confidence":0.0039,"label":"porn"},{"confidence":0.0078,"label":"sexy"}],"terrorism":[{"confidence":0.0002,"label":"terrorist"},{"confidence":0.0002,"label":"fascist"},{"confidence":0.0001,"label":"cult"},{"confidence":0.0001,"label":"kidnap"},{"confidence":0.0006,"label":"riot"},{"confidence":0.0001,"label":"parade"},{"confidence":0.0002,"label":"corpse"},{"confidence":0.0001,"label":"bloody"},{"confidence":0.0001,"label":"knife"},{"confidence":0.0001,"label":"gun"},{"confidence":0.0002,"label":"military_weapon"},{"confidence":0,"label":"special_characters"},{"confidence":0.9994,"label":"normal"}],"ad":[{"confidence":0,"label":"ad"},{"confidence":1,"label":"normal"}]},"category_suggestions":{"ad":"pass", ,"porn":"pass","terrorism":"pass"}}]} Process exiting with code: 0 父主题: 图像审核
  • 图像内容审核(V2) 本章节对图像内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以使用Url或Image配置图像信息(代表使用url或者图像的base64),示例中以url为例配置完成后运行即可。 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/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.RunImageModerationRequest{} var listCategoriesbody = []model.ImageDetectionReqCategories{ model.GetImageDetectionReqCategoriesEnum().PORN, model.GetImageDetectionReqCategoriesEnum().TERRORISM, model.GetImageDetectionReqCategoriesEnum().AD, } thresholdImageDetectionReq:= float32(0) moderationRuleImageDetectionReq:= "default" urlImageDetectionReq:= "https://XXX.jpg" //此处替换为公网可以访问的图片地址 request.Body = &model.ImageDetectionReq{ Threshold: &thresholdImageDetectionReq, Categories: &listCategoriesbody, ModerationRule: &moderationRuleImageDetectionReq, Url: &urlImageDetectionReq, } response, err := client.RunImageModeration(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) }} 审核结果输出到控制台表示执行成功,图像内容审核结果输出到控制台。 RunImageModerationResponse {"result":{"detail":{"porn":[{"confidence":0.9883,"label":"normal"},{"confidence":0.0039,"label":"porn"},{"confidence":0.0078,"label":"sexy"}],"terrorism":[{"confidence":0.0002,"label":"terrorist"},{"confidence":0.0002,"label":"fascist"},{"confidence":0.0001,"label":"cult"},{"confidence":0.0001,"label":"kidnap"},{"confidence":0.0006,"label":"riot"},{"confidence":0.0001,"label":"parade"},{"confidence":0.0002,"label":"corpse"},{"confidence":0.0001,"label":"bloody"},{"confidence":0.0001,"label":"knife"},{"confidence":0.0001,"label":"gun"},{"confidence":0.0002,"label":"military_weapon"},{"confidence":0,"label":"special_characters"},{"confidence":0.9994,"label":"normal"}],"ad":[{"confidence":0,"label":"ad"},{"confidence":1,"label":"normal"}]},"suggestion":"pass","category_suggestions":{"ad":"pass","porn":"pass","terrorism":"pass"}}} Process exiting with code: 0 父主题: 图像审核
  • 文本内容审核(V2) 本章节对文本内容审核AK/SK方式使用SDK进行示例说明。 示例代码中可以将TextDetectionItemsReq的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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v2/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.RunTextModerationRequest{} typeItemsTextDetectionItemsReq:= "content" var listItemsbody = []model.TextDetectionItemsReq{ { Text: "text", //此处输入待检测文本 Type: &typeItemsTextDetectionItemsReq, }, } var listCategoriesbody = []string{ "porn", "ad", "abuse", "contraband", "flood", } request.Body = &model.TextDetectionReq{ Items: listItemsbody, Categories: &listCategoriesbody, } response, err := client.RunTextModeration(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) }} 审核结果输出到控制台表示执行成功,文本内容审核结果输出到控制台。 RunTextModerationResponse {"result":{"suggestion":"block","detail":{"contraband":["亚砷酸钾"],"porn":["luo聊"]}}} Process exiting with code: 0 父主题: 文本审核
  • SDK列表及指导文档(通用版) API Explorer 能根据需要动态生成SDK代码功能,降低您使用SDK的难度,推荐使用。 SDK中心 提供服务SDK依赖引入的方式。 表1 提供了各个云服务支持的SDK列表,您可以在GitHub仓库查看SDK更新历史、获取安装包以及查看指导文档进行配置。 表1 SDK列表 编程语言 github地址 指导文档 视频指导 JAVA huaweicloud-sdk-java-v3 Java SDK使用指导 Java SDK视频指导 PYTHON huaweicloud-sdk-python-v3 Python SDK使用指导 Python SDK视频指导 .NET huaweicloud-sdk-net-v3 .Net SDK使用指导 - GO huaweicloud-sdk-go-v3 Go SDK使用指导 - PHP huaweicloud-sdk-php-v3 PHP SDK使用指导 - Node.js huaweicloud-sdk-nodejs-v3 Node.js SDK使用指导 -
共100000条