-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06736c3
commit 215a21c
Showing
124 changed files
with
2,042 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
buildToolsVersion "29.0.2" | ||
defaultConfig { | ||
applicationId "com.mnn.llm" | ||
minSdkVersion 21 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
externalNativeBuild { | ||
cmake { | ||
arguments "-DBUILD_JNI=TRUE", "-DANDROID_STL=c++_shared", "-DLLM_SUPPORT_VISION=TRUE", "-DMNN_OPENCL=TRUE" | ||
abiFilters 'arm64-v8a' | ||
} | ||
} | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path file('../../CMakeLists.txt') | ||
} | ||
} | ||
sourceSets { | ||
main { | ||
jniLibs.srcDirs = ['src/main/jni/libs'] | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
packagingOptions { | ||
exclude("META-INF/DEPENDENCIES") | ||
exclude("META-INF/LICENSE") | ||
exclude("META-INF/LICENSE.txt") | ||
exclude("META-INF/license.txt") | ||
exclude("META-INF/NOTICE") | ||
exclude("META-INF/NOTICE.txt") | ||
exclude("META-INF/notice.txt") | ||
exclude("META-INF/ASL2.0") | ||
exclude("META-INF/*.kotlin_module") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' | ||
implementation 'androidx.recyclerview:recyclerview:1.1.0' | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support:design:28.0.0' | ||
implementation 'uk.co.chrisjenx:calligraphy:2.2.0' | ||
implementation 'com.android.support:support-v4:28.0.0' | ||
implementation 'com.google.android.material:material:1.0.0' | ||
implementation "com.squareup.okhttp3:okhttp:4.11.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
29 changes: 29 additions & 0 deletions
29
transformers/llm/engine/android/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mnn.llm"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:screenOrientation= "portrait" | ||
> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".Conversation" | ||
android:screenOrientation= "portrait" | ||
android:theme="@style/AppTheme.Trans"> | ||
</activity> | ||
</application> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
</manifest> |
Binary file added
BIN
+129 KB
transformers/llm/engine/android/app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions
54
transformers/llm/engine/android/app/src/main/java/com/mnn/llm/BaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.mnn.llm; | ||
|
||
import android.content.Context; | ||
//import android.support.annotation.DrawableRes; | ||
//import android.support.v7.app.AppCompatActivity; | ||
//import android.support.v7.widget.Toolbar; | ||
import android.view.Menu; | ||
import android.view.MenuInflater; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.DrawableRes; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.widget.Toolbar; | ||
|
||
import com.mnn.llm.R; | ||
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; | ||
|
||
public class BaseActivity extends AppCompatActivity { | ||
Toolbar toolbar; | ||
TextView title; | ||
public final void changeTitle(int toolbarId, String titlePage){ | ||
toolbar = (Toolbar) findViewById(toolbarId); | ||
setSupportActionBar(toolbar); | ||
|
||
title = (TextView) toolbar.findViewById(R.id.tv_title); | ||
title.setText(titlePage); | ||
getSupportActionBar().setTitle(""); | ||
} | ||
public final void setupToolbar(int toolbarId, String titlePage){ | ||
toolbar = (Toolbar) findViewById(toolbarId); | ||
setSupportActionBar(toolbar); | ||
|
||
title = (TextView) toolbar.findViewById(R.id.tv_title); | ||
title.setText(titlePage); | ||
|
||
getSupportActionBar().setTitle(""); | ||
} | ||
public void setupToolbarWithUpNav(int toolbarId, String titlePage, @DrawableRes int res){ | ||
toolbar = (Toolbar) findViewById(toolbarId); | ||
setSupportActionBar(toolbar); | ||
|
||
title = (TextView) toolbar.findViewById(R.id.tv_title); | ||
title.setText(titlePage); | ||
|
||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
getSupportActionBar().setHomeAsUpIndicator(res); | ||
getSupportActionBar().setTitle(""); | ||
} | ||
@Override | ||
protected void attachBaseContext(Context newBase) { | ||
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
transformers/llm/engine/android/app/src/main/java/com/mnn/llm/Chat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mnn.llm; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Chat implements Serializable { | ||
public native boolean Init(String modelDir); | ||
public native String Submit(String input); | ||
public native byte[] Response(); | ||
public native void Done(); | ||
public native void Reset(); | ||
|
||
static { | ||
System.loadLibrary("llm"); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
transformers/llm/engine/android/app/src/main/java/com/mnn/llm/Common.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.mnn.llm; | ||
|
||
import android.app.Activity; | ||
import android.content.res.AssetManager; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
|
||
public class Common { | ||
public static String copyAssetResource2File(Activity activity, String assetsDir) throws IOException, InterruptedException { | ||
AssetManager assetManager = activity.getBaseContext().getAssets(); | ||
// make output dir | ||
String outDir = activity.getCacheDir() + "/" + assetsDir; | ||
File outPath = new File(outDir); | ||
if (!outPath.exists()) { | ||
outPath.mkdirs(); | ||
} | ||
// visit input files and copy | ||
String[] files = assetManager.list(assetsDir); | ||
int nums = files.length; | ||
CopyThread [] threads = new CopyThread[nums]; | ||
for (int i = 0; i < nums; i++) { | ||
System.out.println("MNN_DEBUG: " + files[i]); | ||
String assetsFile = files[i]; | ||
if (new File(outDir + '/' + assetsFile).exists()) { | ||
continue; | ||
} | ||
threads[i] = new CopyThread(assetManager, assetsDir + '/' + assetsFile, outDir + '/' + assetsFile); | ||
threads[i].start(); | ||
} | ||
for (int i = 0; i < nums; i++) { | ||
if (threads[i] != null) { | ||
threads[i].join(); | ||
} | ||
} | ||
return outDir; | ||
} | ||
} | ||
|
||
class CopyThread extends Thread { | ||
private AssetManager mAsset; | ||
private String mSrcPath; | ||
private String mDstPath; | ||
public CopyThread(AssetManager asset, String src, String dst) { | ||
mAsset = asset; | ||
mSrcPath = src; | ||
mDstPath = dst; | ||
} | ||
public void run() { | ||
try { | ||
InputStream inS = mAsset.open(mSrcPath); | ||
File outF = new File(mDstPath); | ||
FileOutputStream outS = new FileOutputStream(outF); | ||
int byteCount; | ||
byte[] buffer = new byte[1024]; | ||
while ((byteCount = inS.read(buffer)) != -1) { | ||
outS.write(buffer, 0, byteCount); | ||
} | ||
outS.flush(); | ||
inS.close(); | ||
outS.close(); | ||
outF.setReadable(true); | ||
} catch (Exception e) {} | ||
} | ||
} |
Oops, something went wrong.