admin管理员组文章数量:1124564
I'm trying to build a flutter chat app by running gemma locally on my device, but I am unable to find clear documentations or video examples for it. All I get now is different exceptions without proper details. like
_Exception (Exception: Platform error: Failed to get gemma response).
I've just created a test application and this is the code:
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_gemma/flutter_gemma.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const GemmaPage(),
);
}
}
class GemmaPage extends StatefulWidget {
const GemmaPage({super.key});
@override
State<GemmaPage> createState() => _GemmaPageState();
}
class _GemmaPageState extends State<GemmaPage> {
bool _isModelInitialized = false;
int? _loadingProgress;
String? _error;
Future<void> _initializeModel() async {
log('entering _initializeModel');
bool isLoaded = await FlutterGemmaPlugin.instance.isLoaded;
log("isloaded: $isLoaded");
if (!isLoaded) {
log('loading model');
await for (int progress in FlutterGemmaPlugin.instance
.loadAssetModelWithProgress(fullPath: 'model.bin')) {
setState(() {
_loadingProgress = progress;
log("progress: $progress");
});
}
}
log('initializing model');
await FlutterGemmaPlugin.instance.init(
maxTokens: 512,
temperature: 1.0,
topK: 1,
randomSeed: 1,
);
setState(() {
_isModelInitialized = true;
});
}
@override
void initState() {
_initializeModel();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Gemma Response:"),
const SizedBox(height: 10), // Added spacing between widgets
ElevatedButton(
onPressed: () async {
final flutterGemma = FlutterGemmaPlugin.instance;
String? response = await flutterGemma.getResponse(
prompt: 'Tell me something interesting',
);
log(response ?? "empty");
},
child: const Text("Test Gemma"),
),
],
),
),
);
}
}
本文标签:
版权声明:本文标题:artificial intelligence - _Exception (Exception: Platform error: Failed to get gemma response) Ondevice Gemma In flutter - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736635088a1945860.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论