Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
android {
namespace = "com.gerfalcon.example.offline_menu_translator"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
ndkVersion = "27.2.12479018"

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
Expand All @@ -32,6 +32,12 @@ android {

buildTypes {
release {
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro"
)
isMinifyEnabled = true
isShrinkResources = true
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
Expand Down
25 changes: 25 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.mediapipe.proto.CalculatorProfileProto$CalculatorProfile
-dontwarn com.google.mediapipe.proto.GraphTemplateProto$CalculatorGraphTemplate
-dontwarn com.google.protobuf.Internal$ProtoMethodMayReturnNull
-dontwarn com.google.protobuf.Internal$ProtoNonnullApi
-dontwarn com.google.protobuf.ProtoField
-dontwarn com.google.protobuf.ProtoPresenceBits
-dontwarn com.google.protobuf.ProtoPresenceCheckedField
-dontwarn javax.lang.model.SourceVersion
-dontwarn javax.lang.model.element.Element
-dontwarn javax.lang.model.element.ElementKind
-dontwarn javax.lang.model.element.Modifier
-dontwarn javax.lang.model.type.TypeMirror
-dontwarn javax.lang.model.type.TypeVisitor
-dontwarn javax.lang.model.util.SimpleTypeVisitor8
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE
21 changes: 18 additions & 3 deletions lib/ui/translator_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class _TranslatorScreenState extends State<TranslatorScreen> {
_downloadProgress = null;
});

final path = await _downloaderDataSource.getFilePath();
await gemma.modelManager.setModelPath(path);

_inferenceModel = await gemma.createModel(
modelType: ModelType.gemmaIt,
supportImage: true,
Expand Down Expand Up @@ -325,11 +328,23 @@ class _TranslatorScreenState extends State<TranslatorScreen> {

// 1. Create the user's message object.
// Use a default prompt if the user only provides an image.
final userMessage = Message.withImage(
text: text.isNotEmpty ? text : "Please translate this menu into English.",
imageBytes: image!,
Message userMessage;
if (image == null || image.isEmpty) {
userMessage = Message.text(
text: text.isNotEmpty
? text
: "Please translate this menu into English.",
isUser: true,
);
} else {
userMessage = Message.withImage(
text: text.isNotEmpty
? text
: "Please translate this menu into English.",
imageBytes: image,
isUser: true,
);
}

// 2. Add the user's message to the UI and clear the input fields.
setState(() {
Expand Down