@@ -69,8 +69,11 @@ class Program
69
69
// </snippet_text_vars>
70
70
71
71
// CREATE HUMAN REVIEWS FOR IMAGES
72
+ // <snippet_review_urls>
72
73
// The list of URLs of the images to create review jobs for.
73
74
private static readonly string [ ] IMAGE_URLS_FOR_REVIEW = new string [ ] { "https://moderatorsampleimages.blob.core.windows.net/samples/sample5.png" } ;
75
+ // </snippet_review_urls>
76
+ // <snippet_review_vars>
74
77
// The name of the team to assign the review to. Must be the team name used to create your Content Moderator website account.
75
78
// If you do not yet have an account, follow this: https://docs.microsoft.com/en-us/azure/cognitive-services/content-moderator/quick-start
76
79
// Select the gear symbol (settings)-->Credentials to retrieve it. Your team name is the Id associated with your subscription.
@@ -79,6 +82,7 @@ class Program
79
82
// For example: https://westus.api.cognitive.microsoft.com/contentmoderator/review/v1.0
80
83
// As reviewers complete reviews, results are sent using an HTTP POST request.
81
84
private static readonly string ReviewsEndpoint = Environment . GetEnvironmentVariable ( "CONTENT_MODERATOR_REVIEWS_ENDPOINT" ) ;
85
+ // </snippet_review_vars>
82
86
83
87
static void Main ( string [ ] args )
84
88
{
@@ -102,8 +106,10 @@ static void Main(string[] args)
102
106
ModerateText ( clientText , TextFile , TextOutputFile ) ;
103
107
// </snippet_textmod_call>
104
108
109
+ // <snippet_review_call>
105
110
// Create image reviews for human reviewers
106
111
CreateReviews ( clientReviews , IMAGE_URLS_FOR_REVIEW , TEAM_NAME , ReviewsEndpoint ) ;
112
+ // </snippet_review_call>
107
113
108
114
Console . WriteLine ( ) ;
109
115
Console . WriteLine ( "End of the quickstart." ) ;
@@ -124,7 +130,7 @@ public static ContentModeratorClient Authenticate(string key, string endpoint)
124
130
return client ;
125
131
}
126
132
127
- // <snippet_imagemod >
133
+ // <snippet_imagemod_iterate >
128
134
/*
129
135
* IMAGE MODERATION
130
136
* This example moderates images from URLs.
@@ -150,6 +156,8 @@ public static void ModerateImages(ContentModeratorClient client, string urlFile,
150
156
{
151
157
Console . WriteLine ( "Evaluating {0}..." , Path . GetFileName ( line ) ) ;
152
158
var imageUrl = new BodyModel ( "URL" , line . Trim ( ) ) ;
159
+ // </snippet_imagemod_iterate>
160
+ // <snippet_imagemod_analyze>
153
161
var imageData = new EvaluationData
154
162
{
155
163
ImageUrl = imageUrl . Value ,
@@ -175,6 +183,8 @@ public static void ModerateImages(ContentModeratorClient client, string urlFile,
175
183
}
176
184
}
177
185
}
186
+ // </snippet_imagemod_analyze>
187
+ // <snippet_imagemod_save>
178
188
// Save the moderation results to a file.
179
189
using ( StreamWriter outputWriter = new StreamWriter ( outputFile , false ) )
180
190
{
@@ -189,6 +199,7 @@ public static void ModerateImages(ContentModeratorClient client, string urlFile,
189
199
Console . WriteLine ( ) ;
190
200
}
191
201
}
202
+ // </snippet_imagemod_save>
192
203
193
204
// <snippet_dataclass>
194
205
// Contains the image moderation results for an image,
@@ -268,7 +279,7 @@ public static void ModerateText(ContentModeratorClient client, string inputFile,
268
279
*
269
280
* Prerequisistes:
270
281
* 1. In your Content Moderator resource go to Resource Management -> Properties, then copy your Resource ID.
271
- * 2. Go to the Content Moderator website, https://{YOUR REGION}.contentmoderator.cognitive.microsoft.com .
282
+ * 2. Go to the Content Moderator website.
272
283
* 3. Click the gear sign (Settings) and go to "Credentials".
273
284
* 4. Under "Whitelisted Resource Id(s)" paste your Resource ID, then select the "+" button to add it.
274
285
* This enables the website to receive programmatic reviews from your Content Moderator resource in Azure.
@@ -278,6 +289,7 @@ public static void ModerateText(ContentModeratorClient client, string inputFile,
278
289
* Use your Azure account with the review APIs:
279
290
* https://docs.microsoft.com/en-us/azure/cognitive-services/content-moderator/review-tool-user-guide/configure
280
291
*/
292
+ // <snippet_review_item>
281
293
// Associates the review ID (assigned by the service) to the internal.
282
294
public class ReviewItem
283
295
{
@@ -290,7 +302,9 @@ public class ReviewItem
290
302
// The ID that the service assigned to the review.
291
303
public string ReviewId ;
292
304
}
305
+ // </snippet_review_item>
293
306
307
+ // <snippet_createreview_fields>
294
308
// Create the reviews using the fixed list of images.
295
309
private static void CreateReviews ( ContentModeratorClient client , string [ ] ImageUrls , string teamName , string endpoint )
296
310
{
@@ -324,7 +338,9 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
324
338
325
339
// The cached review information, associating a local content ID to the created review ID for each item.
326
340
List < ReviewItem > reviewItems = new List < ReviewItem > ( ) ;
341
+ // </snippet_createreview_fields>
327
342
343
+ // <snippet_createreview_create>
328
344
using ( TextWriter outputWriter = new StreamWriter ( OutputFile , false ) )
329
345
{
330
346
writer = outputWriter ;
@@ -361,7 +377,9 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
361
377
}
362
378
363
379
var reviewResponse = client . Reviews . CreateReviewsWithHttpMessagesAsync ( "application/json" , teamName , requestInfo ) ;
380
+ // </snippet_createreview_create>
364
381
382
+ // <snippet_createreview_ids>
365
383
// Update the local cache to associate the created review IDs with the associated content.
366
384
var reviewIds = reviewResponse . Result . Body ;
367
385
for ( int i = 0 ; i < reviewIds . Count ; i ++ ) { reviewItems [ i ] . ReviewId = reviewIds [ i ] ; }
@@ -380,7 +398,9 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
380
398
WriteLine ( outputWriter , JsonConvert . SerializeObject ( reviewDetail . Result . Body , Formatting . Indented ) ) ;
381
399
Thread . Sleep ( throttleRate ) ;
382
400
}
401
+ // </snippet_createreview_ids>
383
402
403
+ // <snippet_createreview_results>
384
404
Console . WriteLine ( ) ;
385
405
Console . WriteLine ( "Perform manual reviews on the Content Moderator site." ) ;
386
406
Console . WriteLine ( "Then, press any key to continue." ) ;
@@ -412,14 +432,17 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
412
432
}
413
433
Console . WriteLine ( "--------------------------------------------------------------" ) ;
414
434
}
435
+ // </snippet_createreview_results>
415
436
437
+ // <snippet_writeline>
416
438
// Helper function that writes a message to the log file, and optionally to the console.
417
439
// If echo is set to true, details will be written to the console.
418
440
private static void WriteLine ( TextWriter writer , string message = null , bool echo = true )
419
441
{
420
442
writer . WriteLine ( message ?? String . Empty ) ;
421
443
if ( echo ) { Console . WriteLine ( message ?? String . Empty ) ; }
422
444
}
445
+ // </snippet_writeline>
423
446
/*
424
447
* END - CREATE HUMAN IMAGE REVIEWS
425
448
*/
0 commit comments