I am trying to use the tflite_flutter and tflite_flutter_helper_plus libraries in the following versions:
`dependencies:
flutter:
sdk: flutter
tflite_flutter: ^0.10.4
tflite_flutter_helper_plus: ^0.0.2`
Here is my implementation, which follows the documentation.
https://github.com/odejinmi/tflite_flutter_helper_plus
<code>import 'package:flutter/material.dart';
import 'package:tflite_flutter_helper_plus/tflite_flutter_helper_plus.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
Widget build(BuildContext context) {
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
State<MyHomePage> createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
onPressed: () { getAnswer();},
child: Text('click me to get answer'),
String question = "What is the capital of Brazil?";
String context = "Brazil is a country in South America. It is the largest country in South America and the fifth largest country in the world. The capital of Brazil is Brasília.";
final bertQuestionAnswerer = await BertQuestionAnswerer.createFromAsset('assets/bert_qa.tflite');
List<QaAnswer> answeres = bertQuestionAnswerer.answer(context, question);
<code>import 'package:flutter/material.dart';
import 'package:tflite_flutter_helper_plus/tflite_flutter_helper_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: TextButton(
onPressed: () { getAnswer();},
child: Text('click me to get answer'),
),
)
);
}
void getAnswer() async {
String question = "What is the capital of Brazil?";
String context = "Brazil is a country in South America. It is the largest country in South America and the fifth largest country in the world. The capital of Brazil is Brasília.";
final bertQuestionAnswerer = await BertQuestionAnswerer.createFromAsset('assets/bert_qa.tflite');
List<QaAnswer> answeres = bertQuestionAnswerer.answer(context, question);
print(answeres);
}
}
</code>
import 'package:flutter/material.dart';
import 'package:tflite_flutter_helper_plus/tflite_flutter_helper_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: TextButton(
onPressed: () { getAnswer();},
child: Text('click me to get answer'),
),
)
);
}
void getAnswer() async {
String question = "What is the capital of Brazil?";
String context = "Brazil is a country in South America. It is the largest country in South America and the fifth largest country in the world. The capital of Brazil is Brasília.";
final bertQuestionAnswerer = await BertQuestionAnswerer.createFromAsset('assets/bert_qa.tflite');
List<QaAnswer> answeres = bertQuestionAnswerer.answer(context, question);
print(answeres);
}
}
But I am getting this error:
<code>E/flutter (12951): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libtask_text_jni.so': dlopen failed: library "libtask_text_jni.so" not found
E/flutter (12951): #0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
E/flutter (12951): #1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
E/flutter (12951): #2 tflitelib.<anonymous closure> (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart:32:27)
E/flutter (12951): #3 tflitelib (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart:40:2)
E/flutter (12951): #4 tflitelib (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart)
E/flutter (12951): #5 BertQuestionAnswererFromFile (package:tflite_flutter_helper_plus/src/task/bindings/text/qa/bert_qa.dart:13:32)
E/flutter (12951): #6 BertQuestionAnswererFromFile (package:tflite_flutter_helper_plus/src/task/bindings/text/qa/bert_qa.dart)
E/flutter (12951): #7 BertQuestionAnswerer.create (package:tflite_flutter_helper_plus/src/task/text/qa/bert_question_answerer.dart:42:23)
E/flutter (12951): #8 BertQuestionAnswerer.createFromAsset (package:tflite_flutter_helper_plus/src/task/text/qa/bert_question_answerer.dart:78:12)
E/flutter (12951): <asynchronous suspension>
E/flutter (12951): #9 _MyHomePageState.getAnswer (package:bert_qa_teste/main.dart:56:34)
E/flutter (12951): <asynchronous suspension>
<code>E/flutter (12951): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libtask_text_jni.so': dlopen failed: library "libtask_text_jni.so" not found
E/flutter (12951): #0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
E/flutter (12951): #1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
E/flutter (12951): #2 tflitelib.<anonymous closure> (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart:32:27)
E/flutter (12951): #3 tflitelib (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart:40:2)
E/flutter (12951): #4 tflitelib (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart)
E/flutter (12951): #5 BertQuestionAnswererFromFile (package:tflite_flutter_helper_plus/src/task/bindings/text/qa/bert_qa.dart:13:32)
E/flutter (12951): #6 BertQuestionAnswererFromFile (package:tflite_flutter_helper_plus/src/task/bindings/text/qa/bert_qa.dart)
E/flutter (12951): #7 BertQuestionAnswerer.create (package:tflite_flutter_helper_plus/src/task/text/qa/bert_question_answerer.dart:42:23)
E/flutter (12951): #8 BertQuestionAnswerer.createFromAsset (package:tflite_flutter_helper_plus/src/task/text/qa/bert_question_answerer.dart:78:12)
E/flutter (12951): <asynchronous suspension>
E/flutter (12951): #9 _MyHomePageState.getAnswer (package:bert_qa_teste/main.dart:56:34)
E/flutter (12951): <asynchronous suspension>
E/flutter (12951):
</code>
E/flutter (12951): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libtask_text_jni.so': dlopen failed: library "libtask_text_jni.so" not found
E/flutter (12951): #0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
E/flutter (12951): #1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
E/flutter (12951): #2 tflitelib.<anonymous closure> (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart:32:27)
E/flutter (12951): #3 tflitelib (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart:40:2)
E/flutter (12951): #4 tflitelib (package:tflite_flutter_helper_plus/src/task/bindings/dlib.dart)
E/flutter (12951): #5 BertQuestionAnswererFromFile (package:tflite_flutter_helper_plus/src/task/bindings/text/qa/bert_qa.dart:13:32)
E/flutter (12951): #6 BertQuestionAnswererFromFile (package:tflite_flutter_helper_plus/src/task/bindings/text/qa/bert_qa.dart)
E/flutter (12951): #7 BertQuestionAnswerer.create (package:tflite_flutter_helper_plus/src/task/text/qa/bert_question_answerer.dart:42:23)
E/flutter (12951): #8 BertQuestionAnswerer.createFromAsset (package:tflite_flutter_helper_plus/src/task/text/qa/bert_question_answerer.dart:78:12)
E/flutter (12951): <asynchronous suspension>
E/flutter (12951): #9 _MyHomePageState.getAnswer (package:bert_qa_teste/main.dart:56:34)
E/flutter (12951): <asynchronous suspension>
E/flutter (12951):
I tried changing the Android version by emulating more recent versions. I would like to understand this error and, if possible, get a solution.