Skip to main content

mediapipe_decision 0.1.2 copy "mediapipe_decision: ^0.1.2" to clipboard
mediapipe_decision: ^0.1.2 copied to clipboard

Google's MediaPipe Decision Maker for Flutter: yes-or-no, choice and score questions about a text, answered with calibrated probabilities.

example/example.dart

import 'dart:io';

import 'package:mediapipe_decision/mediapipe_decision.dart';

/// Answers a yes-or-no and a choice question about a text from the command
/// line with Google's pinned Laya model:
/// `dart run example/example.dart "My order arrived broken."`.
///
/// A Dart program has no app bundle, so this downloads the model (678 MB) once
/// into `.dart_tool/mediapipe_models/`, checks its SHA-256 and passes its
/// path. A Flutter app passes `model: DecisionModels.layaS256` instead, after
/// setting `ModelStore.allowDownloads = true` or bundling the model.
Future<void> main(List<String> arguments) async {
  final store = ModelStore(
    cacheDirectory: Directory('.dart_tool/mediapipe_models').absolute.path,
  );
  final model = await store.get(DecisionModels.layaS256);
  final task = await DecisionMaker.create(
    DecisionMakerOptions(modelPath: model.path),
  );
  try {
    final text = arguments.join(' ');
    final refund = await task.evaluateBoolean(
      text,
      BooleanQuestion('The customer wants a refund.'),
    );
    final topic = await task.evaluateChoice(
      text,
      ChoiceQuestion({
        'shipping': 'A problem with delivery or a damaged package',
        'billing': 'A question about a charge or a refund',
        'other': 'Anything else',
      }),
    );
    print(
      'Wants a refund: ${refund.value} '
      '(${refund.probabilityTrue.toStringAsFixed(2)})',
    );
    print('Topic: ${topic.selectedKey}');
  } finally {
    await task.dispose();
  }
}
0
likes
160
points
--
downloads

Documentation

API reference

Publisher

verified publishergoogle.dev

Google's MediaPipe Decision Maker for Flutter: yes-or-no, choice and score questions about a text, answered with calibrated probabilities.

Repository (GitHub)
View/report issues
Contributing

Topics

#mediapipe #machine-learning #nlp #classification

License

BSD-3-Clause (license)

Dependencies

code_assets, ffi, flutter, flutter_web_plugins, hooks, mediapipe_core

More

Packages that depend on mediapipe_decision

Packages that implement mediapipe_decision