日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

使用c#接入华为云-内容审核

發(fā)布時(shí)間:2023/12/4 C# 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用c#接入华为云-内容审核 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

背景

內(nèi)容審核(Content Moderation),是基于圖像、文本、音視頻的檢測(cè)技術(shù),可自動(dòng)檢測(cè)涉黃、涉政涉暴、涉政敏感人物、圖文違規(guī)等內(nèi)容,對(duì)用戶上傳的圖片、文字、音視頻進(jìn)行內(nèi)容審核,以滿足上傳要求,幫助客戶降低業(yè)務(wù)違規(guī)風(fēng)險(xiǎn)。

一般涉及到TO C的很多業(yè)務(wù)都會(huì)涉及到。

內(nèi)容審核-圖像

圖像內(nèi)容審核,利用深度神經(jīng)網(wǎng)絡(luò)模型對(duì)圖片內(nèi)容進(jìn)行檢測(cè),準(zhǔn)確識(shí)別圖像中的涉政敏感人物、暴恐元素、涉黃內(nèi)容等,幫助業(yè)務(wù)規(guī)避違規(guī)風(fēng)險(xiǎn)。

內(nèi)容審核-文本

文本內(nèi)容審核,采用人工智能文本檢測(cè)技術(shù)有效識(shí)別涉黃、涉政、廣告、辱罵、違禁品和灌水文本內(nèi)容,提供定制化的文本敏感內(nèi)容審核方案。

需求

最近因?yàn)轫?xiàng)目中需要接入該功能,因?yàn)楣臼鞘褂萌A為云,所以特地找了華為云的內(nèi)容審核服務(wù)。本來想著有sdk應(yīng)該是三下五乘二的事情,結(jié)果看了文檔

沒錯(cuò)人家不和你玩.net,沒辦法只能是退而求其次,使用它的http api。

主要代碼實(shí)現(xiàn)

獲取token

??///?<summary>///?///?</summary>///?<param?name="username"></param>///?<param?name="password"></param>///?<param?name="domainName"></param>///?<param?name="projectName"></param>///?<returns></returns>private?static?String?getToken(String?username,?String?password,?String?domainName,?String?projectName){var?client?=?new?RestClient("https://iam.myhuaweicloud.com/v3/auth/tokens");client.Timeout?=?-1;var?request?=?new?RestRequest(Method.POST);request.AddHeader("Content-Type",?"application/json");var?body?=?"{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"name\":\""?+?username?+?"\",\"password\":\""?+?password?+?"\",\"domain\":{\"name\":\""?+?domainName?+?"\"}}}},\"scope\":{\"project\":{\"name\":\""?+?projectName?+?"\"}}}}";request.AddParameter("application/json",?body,?ParameterType.RequestBody);ServicePointManager.ServerCertificateValidationCallback?=?((a1,?b1,?c1,?d1)?=>?{?return?true;?});ServicePointManager.SecurityProtocol?=?SecurityProtocolType.Tls?|?SecurityProtocolType.Tls11?|?SecurityProtocolType.Tls12?|?(SecurityProtocolType)3072;IRestResponse?response?=?client.Execute(request);if?(response.StatusCode?==?HttpStatusCode.Created){return??response.Headers.FirstOrDefault(o?=>?o.Name?==?"X-Subject-Token")?.Value.ToString()??null;}else{Console.WriteLine("err:"?+?response.Content);}return?null;}

內(nèi)容審核

??private?static?bool?requestModerationTextContentBase64(String?token,?String?textModeration,?String?projectName){var?client?=?new?RestClient("https://moderation."+?projectName?+?".myhuaweicloud.com/v1.0/moderation/text");client.Timeout?=?-1;var?request?=?new?RestRequest(Method.POST);request.AddHeader("X-Auth-Token",?token);request.AddHeader("Content-Type",?"application/json");ModerationTextContentBody?model?=?new?ModerationTextContentBody();List<string>?list?=?new?List<string>{"ad","politics","abuse","porn","contraband","flood"};model.categories.AddRange(list);model.items.Add(new?ItemsItem()?{?type=?"content",?text=?textModeration?});var?body?=?JsonConvert.SerializeObject(model);//"{\"categories\":[\"ad\",\"politics\",\"abuse\",\"porn\",\"contraband\",\"flood\"],\"items\":[{\"text\":\""+?textModeration?+?"\",\"type\":\"content\"}]}";request.AddParameter("application/json",?body,?ParameterType.RequestBody);IRestResponse?response?=?client.Execute(request);Console.WriteLine(response.Content);if?(response.StatusCode?==?HttpStatusCode.OK){var?r=??JsonConvert.DeserializeObject<ResponseModerationTextContent>(response.Content);??if(r.result.suggestion==?"pass"){return?true;}}else{Console.WriteLine("err:"?+?response.Content);}return?false;}

調(diào)用

???String?token?=?getToken(username,?password,?domainName,?projectName);//??Console.WriteLine(token);string?textModeration?=?@"嗚嗚嗚嗚嗚";var?result=??requestModerationTextContentBase64(token,?textModeration,?projectName);

總結(jié)

以上是生活随笔為你收集整理的使用c#接入华为云-内容审核的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。