MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / textContentFromPrediction

Function textContentFromPrediction

chrome-extension/src/content.js:39–58  ·  view source on GitHub ↗

* Produces a short text string summarizing the prediction * Input prediction should be a list of {className: string, prediction: float} * objects. * @param {[{className: string, predictions: number}]} predictions ordered list * of objects, each with a prediction class and score

(predictions)

Source from the content-addressed store, hash-verified

37 * of objects, each with a prediction class and score
38 */
39function textContentFromPrediction(predictions) {
40 if (!predictions || predictions.length < 1) {
41 return `No prediction 🙁`;
42 }
43 // Confident.
44 if (predictions[0].probability >= HIGH_CONFIDENCE_THRESHOLD) {
45 return `😄 ${predictions[0].className}!`;
46 }
47 // Not Confident.
48 if (predictions[0].probability >= LOW_CONFIDENCE_THRESHOLD &&
49 predictions[0].probability < HIGH_CONFIDENCE_THRESHOLD) {
50 return `${predictions[0].className}?...\n Maybe ${
51 predictions[1].className}?`;
52 }
53 // Very not confident.
54 if (predictions[0].probability < LOW_CONFIDENCE_THRESHOLD) {
55 return `😕 ${predictions[0].className}????...\n Maybe ${
56 predictions[1].className}????`;
57 }
58}
59
60/**
61 * Returns a list of all DOM image elements pointing to the provided srcUrl.

Callers 1

content.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected