Skip to content

TensorFlow Lite BERT QA Android app Update SDK > 35 #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions branchREADME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TensorFlow BERT QA Android\nForked from tensorflow/examples, built with Gradle 8.7, AGP 8.5.0, Kotlin 1.9.20, and compileSdk 35. Tested on SDK36 Beta Pixel9XL virtual \nManaged by Chris-Hamid.
26 changes: 26 additions & 0 deletions lite/examples/bert_qa/android/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Overview:
This project is a fork of the TensorFlow BERT QA Android app from tensorflow/examples, updated to support modern Android development practices. It uses BERT (Bidirectional Encoder Representations from Transformers) for question-answering tasks on mobile devices.

Build Details:
Gradle: 8.7
Android Gradle Plugin (AGP): 8.5.0
Kotlin: 1.9.20
Compile SDK: 35
Tested on: API 36 Beta (Pixel 9 XL virtual emulator)

How to Build and Run :
Clone the repository: ```bash git clone https://github.com/Chris-Hamid/tensorflow-examples.git ```
Open the project in Android Studio (version 2024.1.1 or later recommended).
Ensure the BERT model files are in `lite/examples/bert_qa/android/app/src/main/assets/`:
Download `mobilebert_float.tflite` from https://storage.googleapis.com/download.tensorflow.org/models/tflite/bert_qa/mobilebert_float.tflite
Download `vocab.txt` from https://storage.googleapis.com/download.tensorflow.org/models/tflite/bert_qa/vocab.txt
Sync the project with Gradle (`File > Sync Project with Gradle Files`).
Build and run on an emulator or device with API 26+.
or Build APK & install on device with API 26+

Contributions:
This project is maintained by Chris-Hamid. Contributions are welcome! Please see the TensorFlow contribution guidelines for more details.

License :
This project is licensed under the Apache License 2.0, as per the original TensorFlow repository. See LICENSE for details.
" > lite/examples/bert_qa/android/README.md
52 changes: 11 additions & 41 deletions lite/examples/bert_qa/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,28 @@ plugins {
}

android {
compileSdk 32

namespace 'org.tensorflow.lite.examples.bertqa'
compileSdk 35
defaultConfig {
applicationId "org.tensorflow.lite.examples.bertqa"
minSdk 23
targetSdk 32
targetSdk 35
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}
buildFeatures {
viewBinding true
Expand All @@ -40,58 +38,30 @@ android {
}
}

// import DownloadModels task
project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets'
project.ext.TEST_ASSETS_DIR = projectDir.toString() + '/src/androidTest/assets'

// Download default models; if you wish to use your own models then
// place them in the "assets" directory and comment out this line.
apply from: 'download_models.gradle'

dependencies {
// Kotlin lang
implementation 'androidx.core:core-ktx:1.15.0'

// App compat and UI things
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

// Navigation library
def nav_version = "2.5.0"
def nav_version = "2.7.7"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

// CameraX core library
def camerax_version = '1.2.0-alpha03'
implementation "androidx.camera:camera-core:$camerax_version"

// CameraX Camera2 extensions
implementation "androidx.camera:camera-camera2:$camerax_version"

// CameraX Lifecycle library
implementation "androidx.camera:camera-lifecycle:$camerax_version"

// CameraX View class
implementation "androidx.camera:camera-view:$camerax_version"

//WindowManager
implementation 'androidx.window:window:1.1.0-alpha02'

// Unit testing
testImplementation 'junit:junit:4.13.2'

// Instrumented testing
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

// Gson library
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.guava:guava:28.1-android'

// Import tensorflow library
implementation 'org.tensorflow:tensorflow-lite-task-text:0.3.0'
// Import the GPU delegate plugin Library for GPU inference
implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.9.0'
}
}

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lite/examples/bert_qa/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0'
classpath 'de.undercouch:gradle-download-task:4.1.2'
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7'
classpath 'de.undercouch:gradle-download-task:5.6.0'
}
}

plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'com.android.application' version '8.5.0' apply false // Update to 8.5.0
id 'com.android.library' version '8.5.0' apply false // Update to 8.5.0
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
}

task clean(type: Delete) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading