Skip to content

Commit 15878f8

Browse files
authored
Merge pull request #172 from niedev/development
Integration and optimization of HY-MT and Madlad
2 parents 405f22b + 7969333 commit 15878f8

20 files changed

Lines changed: 2466 additions & 1452 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.apk filter=lfs diff=lfs merge=lfs -text

.idea/.gitignore

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/caches/deviceStreaming.xml

Lines changed: 0 additions & 1041 deletions
This file was deleted.

.idea/gradle.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

apks/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
If you want to early test this version of the app, first of all consider that this is a development preview, so it could be pretty unstable, and it will require initial setup, so to try it you need to:
2+
3+
Download from [here](https://github.com/niedev/OnnxModelsEnhancer/releases/tag/v1.0.0-beta) the Mozilla.zip,
4+
Madlad.zip, HY-MT.zip. After the download extract these folders (their name should remain "Mozilla", "Madlad" and "HY-MT", with the content of these .zip directly inside the corresponding extracted folders, if you change the structure of these folder the app will not work).
5+
6+
After that create a folder named "models", inside it create a folder named "Translation", and inside it paste all the extracted folders.
7+
8+
Now download one of the apk in this folder, install it, open the app, enable the requested file access and start the download.
9+
10+
After the download has finished, exit the app and enable all its permissions from the Android Settings (Settings -> Applications -> RTranslator).
11+
12+
Then re open the app and everything should work.
13+
14+
By default, the models used for translation are the Mozilla ones, to select the other supported model you can select one from RTranslator's settings, at the bottom (note that probably, to execute Madlad and HY-MT, you will need a phone with at least 12GB of RAM, if the RAM won't be enough the app will crash until you wipe its data).

apks/RTranslator_3.0.0_alpha1.apk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:59f7525063e66da7efbd9c32dac2a4810fdf0df1d15137af3efaa66d87604553
3+
size 192110576

app/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ android {
4242
//bergamot flags
4343
'-DANDROID_ABI=arm64-v8a',
4444
'-DANDROID_PLATFORM=android-28',
45-
'-DANDROID_STL=c++_static',
45+
'-DANDROID_STL=c++_shared',
4646
"-DANDROID_PIE=ON",
4747
"-DANDROID_CPP_FEATURES=exceptions",
4848
'-DCMAKE_BUILD_TYPE=Release',
@@ -121,6 +121,11 @@ dependencies {
121121
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
122122
//Download library
123123
implementation 'com.github.amitshekhariitbhu:PRDownloader:1.0.2'
124+
// DJL HuggingFace tokenizers wrapper
125+
implementation "ai.djl.android:core:0.33.0"
126+
implementation "ai.djl.huggingface:tokenizers:0.33.0"
127+
implementation "ai.djl.android:tokenizer-native:0.33.0"
128+
124129
//implementation 'androidx.core:core-ktx:1.10.0'
125130
implementation 'androidx.work:work-runtime:2.7.1'
126131
implementation 'androidx.exifinterface:exifinterface:1.3.7'

app/src/main/java/nie/translator/rtranslator/Global.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656

5757
public class Global extends Application implements DefaultLifecycleObserver {
58-
public static final boolean ONLY_TEXT_TRANSLATION_MODE = true;
58+
public static final boolean ONLY_TEXT_TRANSLATION_MODE = false;
5959
public enum RTranslatorMode {
6060
TEXT_TRANSLATION_MODE,
6161
WALKIE_TALKIE_MODE,
@@ -128,7 +128,18 @@ public void restartTranslator(Translator.GeneralListener listener){
128128
getLanguages(false);
129129
SharedPreferences sharedPreferences = getSharedPreferences("default", Context.MODE_PRIVATE);
130130
int mode = sharedPreferences.getInt("selectedTranslationModel", Translator.MOZILLA);
131-
translator.restart(mode, listener);
131+
translator.restart(mode, new Translator.GeneralListener() {
132+
@Override
133+
public void onSuccess() {
134+
getTranslatorLanguages(false); //refresh languages
135+
listener.onSuccess();
136+
}
137+
138+
@Override
139+
public void onFailure(int[] reasons, long value) {
140+
listener.onFailure(reasons, value);
141+
}
142+
});
132143
}
133144

134145
@Nullable

app/src/main/java/nie/translator/rtranslator/LoadingActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
import android.content.DialogInterface;
2121
import android.content.Intent;
2222
import android.content.SharedPreferences;
23+
import android.net.Uri;
24+
import android.os.Build;
2325
import android.os.Bundle;
26+
import android.os.Environment;
2427
import android.os.Handler;
2528
import android.os.Looper;
29+
import android.provider.Settings;
2630

2731
import androidx.appcompat.app.AlertDialog;
2832
import java.util.ArrayList;

app/src/main/java/nie/translator/rtranslator/access/AccessActivity.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818

1919
import android.Manifest;
2020
import android.content.Context;
21+
import android.content.Intent;
2122
import android.content.SharedPreferences;
23+
import android.net.Uri;
2224
import android.os.Build;
2325
import android.os.Bundle;
26+
import android.os.Environment;
27+
import android.provider.Settings;
2428
import android.view.View;
2529

2630
import androidx.fragment.app.Fragment;
@@ -78,6 +82,12 @@ protected void onStart() {
7882
super.onStart(); //called here because otherwise the onStart of the DownloadFragment is called before this onStart, and this could cause problems.
7983
}
8084

85+
@Override
86+
protected void onResume() {
87+
super.onResume();
88+
checkAllFilesPermission(); //todo: remove before the final release
89+
}
90+
8191
@Override
8292
protected void onStop() {
8393
super.onStop();
@@ -151,6 +161,27 @@ public void onBackPressed() {
151161
}
152162
super.onBackPressed();
153163
}
164+
165+
//todo: remove before the final release
166+
private void checkAllFilesPermission() {
167+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
168+
if (!Environment.isExternalStorageManager()) {
169+
requestAllFilesPermission();
170+
}
171+
}
172+
}
173+
174+
//todo: remove before the final release
175+
private void requestAllFilesPermission() {
176+
try {
177+
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
178+
intent.setData(Uri.parse("package:" + getPackageName()));
179+
startActivityForResult(intent, 100);
180+
} catch (Exception e) {
181+
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
182+
startActivityForResult(intent, 100);
183+
}
184+
}
154185
}
155186

156187

0 commit comments

Comments
 (0)