Content Moderation
Content Moderation
- What's New
- Product Bulletin
- Service Overview
- Getting Started
- User Guide
- API Reference
-
SDK Reference
- Introduction to Moderation SDK
- Applying for a Service
- Obtaining Authentication Information
- Preparing the Environment
- Using the SDK (Java)
- Using the Python SDK
- Using the .NET SDK
- Using the Go SDK
-
FAQs
- Service Enabling
-
APIs
- How Do I Use Content Moderation APIs?
- What Should I Do When I Fail to Call a Content Moderation API?
- Can I Directly Upload a Word File for Text Moderation?
- What Are the Constraints on Concurrent API Calls?
- What Can I Do if the Request for Calling an API Times Out?
- How Do I Customize a Detection in Text Moderation?
- Can Content Moderation Traverse and Review the Content in an OBS Folder?
- Error Codes
- Monitoring
- Others
- Price Details
- Glossary
- General Reference
On this page
Show all
Help Center/
Content Moderation/
SDK Reference/
Using the Go SDK/
SDK Calling Example/
Moderation (Image)/
Image Moderation (V2)
Copied.
Image Moderation (V2)
- This section describes how to use the Image Moderation SDK by AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. You can use either the image or url parameter (representing the URL or Base64 code of the image) to configure the image information. This section uses url as an example.
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
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() { //Enter your AK/SK. ak := "<YOUR AK>" sk := "<YOUR SK>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := moderation.NewModerationClient( moderation.ModerationClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.RunImageModerationRequest{} var listCategoriesbody = []model.ImageDetectionReqCategories{ model.GetImageDetectionReqCategoriesEnum().PORN, } thresholdImageDetectionReq:= float32(0) moderationRuleImageDetectionReq:= "default" urlImageDetectionReq:= "https://XXX.jpg" //Replace it with an image URL that can be accessed from the Internet. 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) }}
- If the moderation result is displayed on the console, the code is successfully executed.
RunImageModerationResponse {"result":{"detail":{"porn":[{"confidence":0.9883,"label":"normal"},{"confidence":0.0039,"label":"porn"},{"confidence":0.0078,"label":"sexy"}]},"suggestion":"pass","category_suggestions":{"porn":"pass",}}} Process exiting with code: 0
Parent topic: Moderation (Image)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot