mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
[Android] add Android UIE JNI support (#885)
* [UIE] init UIE JNI codes * [UIE] init UIE JNI codes * [Android] Add UIE SchemaNode * [Android] Add UIE SchemaNode * [Android] Add AllocateUIECxxSchemaNodeFromJava func * [Android] Add AllocateUIECxxSchemaNodeFromJava func * Delete README_Ру́сский_язы́к.md * Delete README_한국어.md * [Android] add uie utils jni * [Android] add uie-nano model download task * [Android] add uie jni support * [Java] remove log * [Java] remove log
This commit is contained in:
@@ -0,0 +1,242 @@
|
||||
package com.baidu.paddle.fastdeploy.app.examples.text.uie;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.RuntimeOption;
|
||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
||||
import com.baidu.paddle.fastdeploy.text.UIEResult;
|
||||
import com.baidu.paddle.fastdeploy.text.uie.UIEModel;
|
||||
import com.baidu.paddle.fastdeploy.text.uie.SchemaLanguage;
|
||||
import com.baidu.paddle.fastdeploy.ui.Utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class UIEMainActivity extends Activity implements View.OnClickListener {
|
||||
private static final String TAG = UIEMainActivity.class.getSimpleName() + "[FastDeploy][Java]";
|
||||
private ImageView back;
|
||||
private ImageButton btnSettings;
|
||||
private EditText etUIEInput;
|
||||
private EditText etUIESchema;
|
||||
private EditText etUIEOutput;
|
||||
private Button btnUIEAnalysis;
|
||||
private String[] inputTexts;
|
||||
private String[] schemaTexts;
|
||||
|
||||
// Call 'init' and 'release' manually later
|
||||
UIEModel predictor = new UIEModel();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Fullscreen
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
setContentView(R.layout.uie_activity_main);
|
||||
|
||||
// Clear all setting items to avoid app crashing due to the incorrect settings
|
||||
initSettings();
|
||||
|
||||
// Check and request CAMERA and WRITE_EXTERNAL_STORAGE permissions
|
||||
if (!checkAllPermissions()) {
|
||||
requestAllPermissions();
|
||||
}
|
||||
|
||||
// Init the camera preview and UI components
|
||||
initView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// Reload settings and re-initialize the predictor
|
||||
checkAndUpdateSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (predictor != null) {
|
||||
predictor.release();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
// Back from setting page to main page
|
||||
back = findViewById(R.id.iv_back);
|
||||
back.setOnClickListener(this);
|
||||
// Apply UIE predict
|
||||
btnUIEAnalysis = findViewById(R.id.btn_uie_analysis);
|
||||
btnUIEAnalysis.setOnClickListener(this);
|
||||
// UIE input, schema and output texts
|
||||
etUIEInput = findViewById(R.id.et_uie_input);
|
||||
etUIESchema = findViewById(R.id.et_uie_schema);
|
||||
etUIEOutput = findViewById(R.id.et_uie_output);
|
||||
// Setting page
|
||||
btnSettings = findViewById(R.id.btn_settings);
|
||||
btnSettings.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_settings:
|
||||
startActivity(new Intent(UIEMainActivity.this, UIESettingsActivity.class));
|
||||
break;
|
||||
case R.id.iv_back:
|
||||
finish();
|
||||
break;
|
||||
case R.id.btn_uie_analysis:
|
||||
extractTextsInformation();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void extractTextsInformation() {
|
||||
if (updateInputTexts() && updateSchemaTexts()) {
|
||||
// Set schema before predict
|
||||
if (predictor.setSchema(schemaTexts)) {
|
||||
// Apply Information Extraction
|
||||
HashMap<String, UIEResult[]>[] results = predictor.predict(inputTexts);
|
||||
updateOutputTexts(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOutputTexts(HashMap<String, UIEResult[]>[] results) {
|
||||
if (results == null) {
|
||||
etUIEOutput.setText("抽取结果为空");
|
||||
return;
|
||||
}
|
||||
// Merge UIEResult strings -> combinedOutputText
|
||||
String combinedOutputText = UIEResult.printResult(results);
|
||||
// Update output text view (EditText)
|
||||
etUIEOutput.setText(combinedOutputText);
|
||||
}
|
||||
|
||||
public boolean updateInputTexts() {
|
||||
String combinedInputText = etUIEInput.getText().toString();
|
||||
if (combinedInputText == null || combinedInputText.length() == 0) {
|
||||
// Use default text if no custom text
|
||||
combinedInputText = getString(R.string.UIE_INPUT_TEXTS_DEFAULT);
|
||||
}
|
||||
String[] texts = combinedInputText.split("[。!!:;:;]");
|
||||
if (texts.length <= 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < texts.length; ++i) {
|
||||
texts[i] = texts[i].trim();
|
||||
}
|
||||
// Update input texts
|
||||
inputTexts = texts;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateSchemaTexts() {
|
||||
String combinedSchemaText = etUIESchema.getText().toString();
|
||||
if (combinedSchemaText == null || combinedSchemaText.length() == 0) {
|
||||
// Use default schema if no custom schema
|
||||
combinedSchemaText = getString(R.string.UIE_SCHEMA_DEFAULT);
|
||||
}
|
||||
String[] schemas = combinedSchemaText.split("[,,|、:;:;]");
|
||||
if (schemas.length <= 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < schemas.length; ++i) {
|
||||
schemas[i] = schemas[i].trim();
|
||||
}
|
||||
|
||||
// Update schema texts
|
||||
schemaTexts = schemas;
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
public void initSettings() {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
UIESettingsActivity.resetSettings();
|
||||
}
|
||||
|
||||
public void checkAndUpdateSettings() {
|
||||
if (UIESettingsActivity.checkAndUpdateSettings(this)) {
|
||||
String realModelDir = getCacheDir() + "/" + UIESettingsActivity.modelDir;
|
||||
Utils.copyDirectoryFromAssets(this, UIESettingsActivity.modelDir, realModelDir);
|
||||
|
||||
String modelFile = realModelDir + "/" + "inference.pdmodel";
|
||||
String paramsFile = realModelDir + "/" + "inference.pdiparams";
|
||||
String vocabFile = realModelDir + "/" + "vocab.txt";
|
||||
RuntimeOption option = new RuntimeOption();
|
||||
option.setCpuThreadNum(UIESettingsActivity.cpuThreadNum);
|
||||
option.setLitePowerMode(UIESettingsActivity.cpuPowerMode);
|
||||
if (Boolean.parseBoolean(UIESettingsActivity.enableLiteFp16)) {
|
||||
option.enableLiteFp16();
|
||||
}
|
||||
predictor.init(modelFile, paramsFile, vocabFile,
|
||||
0.3f, 128, schemaTexts,
|
||||
option, SchemaLanguage.ZH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (grantResults[0] != PackageManager.PERMISSION_GRANTED || grantResults[1] != PackageManager.PERMISSION_GRANTED) {
|
||||
new AlertDialog.Builder(UIEMainActivity.this)
|
||||
.setTitle("Permission denied")
|
||||
.setMessage("Click to force quit the app, then open Settings->Apps & notifications->Target " +
|
||||
"App->Permissions to grant all of the permissions.")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
UIEMainActivity.this.finish();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void requestAllPermissions() {
|
||||
ActivityCompat.requestPermissions(
|
||||
this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
0);
|
||||
}
|
||||
|
||||
private boolean checkAllPermissions() {
|
||||
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
== PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.baidu.paddle.fastdeploy.app.examples.text.uie;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
||||
import com.baidu.paddle.fastdeploy.ui.Utils;
|
||||
import com.baidu.paddle.fastdeploy.ui.view.AppCompatPreferenceActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UIESettingsActivity extends AppCompatPreferenceActivity implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String TAG = UIESettingsActivity.class.getSimpleName();
|
||||
static public int selectedModelIdx = -1;
|
||||
static public String modelDir = "";
|
||||
static public int cpuThreadNum = 2;
|
||||
static public String cpuPowerMode = "";
|
||||
static public String enableLiteFp16 = "true";
|
||||
|
||||
ListPreference lpChoosePreInstalledModel = null;
|
||||
EditTextPreference etModelDir = null;
|
||||
ListPreference lpCPUThreadNum = null;
|
||||
ListPreference lpCPUPowerMode = null;
|
||||
ListPreference lpEnableLiteFp16 = null;
|
||||
|
||||
List<String> preInstalledModelDirs = null;
|
||||
List<String> preInstalledCPUThreadNums = null;
|
||||
List<String> preInstalledCPUPowerModes = null;
|
||||
List<String> preInstalledEnableLiteFp16s = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.uie_settings);
|
||||
ActionBar supportActionBar = getSupportActionBar();
|
||||
if (supportActionBar != null) {
|
||||
supportActionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
// Initialize pre-installed models
|
||||
preInstalledModelDirs = new ArrayList<String>();
|
||||
preInstalledCPUThreadNums = new ArrayList<String>();
|
||||
preInstalledCPUPowerModes = new ArrayList<String>();
|
||||
preInstalledEnableLiteFp16s = new ArrayList<String>();
|
||||
preInstalledModelDirs.add(getString(R.string.UIE_MODEL_DIR_DEFAULT));
|
||||
preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
||||
preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
|
||||
preInstalledEnableLiteFp16s.add(getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT));
|
||||
|
||||
// Setup UI components
|
||||
lpChoosePreInstalledModel =
|
||||
(ListPreference) findPreference(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY));
|
||||
String[] preInstalledModelNames = new String[preInstalledModelDirs.size()];
|
||||
for (int i = 0; i < preInstalledModelDirs.size(); i++) {
|
||||
preInstalledModelNames[i] = preInstalledModelDirs.get(i).substring(preInstalledModelDirs.get(i).lastIndexOf("/") + 1);
|
||||
}
|
||||
lpChoosePreInstalledModel.setEntries(preInstalledModelNames);
|
||||
lpChoosePreInstalledModel.setEntryValues(preInstalledModelDirs.toArray(new String[preInstalledModelDirs.size()]));
|
||||
lpCPUThreadNum = (ListPreference) findPreference(getString(R.string.CPU_THREAD_NUM_KEY));
|
||||
lpCPUPowerMode = (ListPreference) findPreference(getString(R.string.CPU_POWER_MODE_KEY));
|
||||
etModelDir = (EditTextPreference) findPreference(getString(R.string.MODEL_DIR_KEY));
|
||||
etModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
|
||||
lpEnableLiteFp16 = (ListPreference) findPreference(getString(R.string.ENABLE_LITE_FP16_MODE_KEY));
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
private void reloadSettingsAndUpdateUI() {
|
||||
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
||||
|
||||
String selected_model_dir = sharedPreferences.getString(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY),
|
||||
getString(R.string.UIE_MODEL_DIR_DEFAULT));
|
||||
int selected_model_idx = lpChoosePreInstalledModel.findIndexOfValue(selected_model_dir);
|
||||
if (selected_model_idx >= 0 && selected_model_idx < preInstalledModelDirs.size() && selected_model_idx != selectedModelIdx) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString(getString(R.string.MODEL_DIR_KEY), preInstalledModelDirs.get(selected_model_idx));
|
||||
editor.putString(getString(R.string.CPU_THREAD_NUM_KEY), preInstalledCPUThreadNums.get(selected_model_idx));
|
||||
editor.putString(getString(R.string.CPU_POWER_MODE_KEY), preInstalledCPUPowerModes.get(selected_model_idx));
|
||||
editor.putString(getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT), preInstalledEnableLiteFp16s.get(selected_model_idx));
|
||||
editor.commit();
|
||||
lpChoosePreInstalledModel.setSummary(selected_model_dir);
|
||||
selectedModelIdx = selected_model_idx;
|
||||
}
|
||||
|
||||
String model_dir = sharedPreferences.getString(getString(R.string.MODEL_DIR_KEY),
|
||||
getString(R.string.UIE_MODEL_DIR_DEFAULT));
|
||||
String cpu_thread_num = sharedPreferences.getString(getString(R.string.CPU_THREAD_NUM_KEY),
|
||||
getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
||||
String cpu_power_mode = sharedPreferences.getString(getString(R.string.CPU_POWER_MODE_KEY),
|
||||
getString(R.string.CPU_POWER_MODE_DEFAULT));
|
||||
String enable_lite_fp16 = sharedPreferences.getString(getString(R.string.ENABLE_LITE_FP16_MODE_KEY),
|
||||
getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT));
|
||||
|
||||
etModelDir.setSummary(model_dir);
|
||||
lpCPUThreadNum.setValue(cpu_thread_num);
|
||||
lpCPUThreadNum.setSummary(cpu_thread_num);
|
||||
lpCPUPowerMode.setValue(cpu_power_mode);
|
||||
lpCPUPowerMode.setSummary(cpu_power_mode);
|
||||
lpEnableLiteFp16.setValue(enable_lite_fp16);
|
||||
lpEnableLiteFp16.setSummary(enable_lite_fp16);
|
||||
|
||||
}
|
||||
|
||||
static boolean checkAndUpdateSettings(Context ctx) {
|
||||
boolean settingsChanged = false;
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
|
||||
String model_dir = sharedPreferences.getString(ctx.getString(R.string.MODEL_DIR_KEY),
|
||||
ctx.getString(R.string.UIE_MODEL_DIR_DEFAULT));
|
||||
settingsChanged |= !modelDir.equalsIgnoreCase(model_dir);
|
||||
modelDir = model_dir;
|
||||
|
||||
String cpu_thread_num = sharedPreferences.getString(ctx.getString(R.string.CPU_THREAD_NUM_KEY),
|
||||
ctx.getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
||||
settingsChanged |= cpuThreadNum != Integer.parseInt(cpu_thread_num);
|
||||
cpuThreadNum = Integer.parseInt(cpu_thread_num);
|
||||
|
||||
String cpu_power_mode = sharedPreferences.getString(ctx.getString(R.string.CPU_POWER_MODE_KEY),
|
||||
ctx.getString(R.string.CPU_POWER_MODE_DEFAULT));
|
||||
settingsChanged |= !cpuPowerMode.equalsIgnoreCase(cpu_power_mode);
|
||||
cpuPowerMode = cpu_power_mode;
|
||||
|
||||
String enable_lite_fp16 = sharedPreferences.getString(ctx.getString(R.string.ENABLE_LITE_FP16_MODE_KEY),
|
||||
ctx.getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT));
|
||||
settingsChanged |= !enableLiteFp16.equalsIgnoreCase(enable_lite_fp16);
|
||||
enableLiteFp16 = enable_lite_fp16;
|
||||
|
||||
return settingsChanged;
|
||||
}
|
||||
|
||||
static void resetSettings() {
|
||||
selectedModelIdx = -1;
|
||||
modelDir = "";
|
||||
cpuThreadNum = 2;
|
||||
cpuPowerMode = "";
|
||||
enableLiteFp16 = "true";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
reloadSettingsAndUpdateUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
reloadSettingsAndUpdateUI();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baidu.paddle.fastdeploy.app.examples.text.uie;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
||||
|
||||
public class UIEWelcomeActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
);
|
||||
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
}
|
||||
setContentView(R.layout.uie_welcome);
|
||||
}
|
||||
|
||||
public void startActivity(View view) {
|
||||
Intent intent = new Intent(UIEWelcomeActivity.this, UIEMainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
97
java/android/app/src/main/res/layout/uie_activity_main.xml
Normal file
97
java/android/app/src/main/res/layout/uie_activity_main.xml
Normal file
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.baidu.paddle.fastdeploy.ui.layout.ActionBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:cropToPadding="true"
|
||||
android:paddingLeft="40px"
|
||||
android:paddingTop="60px"
|
||||
android:paddingRight="60px"
|
||||
android:paddingBottom="40px"
|
||||
android:src="@drawable/back_btn" />
|
||||
|
||||
<TextView
|
||||
style="@style/action_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="50px"
|
||||
android:text="@string/uie_app_name"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_settings"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="10dp"
|
||||
android:background="@null"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/btn_settings" />
|
||||
</com.baidu.paddle.fastdeploy.ui.layout.ActionBarLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_uie_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:lines="3"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="@string/UIE_INPUT_TEXTS_HINT"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_uie_schema"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:lines="3"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="@string/UIE_SCHEMA_HINT"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_uie_analysis"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:textSize="20sp"
|
||||
android:text="开始抽取信息" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_uie_output"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="20sp"
|
||||
android:lines="4"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="信息抽取结果:" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
76
java/android/app/src/main/res/layout/uie_welcome.xml
Normal file
76
java/android/app/src/main/res/layout/uie_welcome.xml
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:background="@drawable/main_bk"
|
||||
/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/model_text"
|
||||
android:layout_width="320dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="120dp"
|
||||
android:background="@color/colorStartBtn"
|
||||
android:gravity="center"
|
||||
android:text="UIE Nano"
|
||||
android:textColor="@color/colorTextWrite"
|
||||
android:textSize="30sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/baidu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/model_text"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="百度FastDeploy"
|
||||
android:textColor="@color/colorTextWrite"
|
||||
android:textSize="22sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/baidu"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="Powered by EasyEdge"
|
||||
android:textColor="@color/colorTextWrite"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<Button
|
||||
|
||||
android:id="@+id/start_ui_activity"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="70dp"
|
||||
android:background="@drawable/round_corner_btn"
|
||||
android:text="@string/start_ui_activity"
|
||||
android:textColor="@color/colorTextWrite"
|
||||
android:textSize="22sp"
|
||||
android:onClick="startActivity"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logo"
|
||||
android:layout_width="95dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="@drawable/paddle_logo"
|
||||
android:scaleType="centerCrop" />
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
@@ -1,14 +1,15 @@
|
||||
<resources>
|
||||
<!-- Default App name -->
|
||||
<string name="app_name">EasyEdge</string>
|
||||
<string name="app_name">FastDeploy</string>
|
||||
<!-- Other App name -->
|
||||
<string name="detection_app_name">EasyEdge</string>
|
||||
<string name="ocr_app_name">EasyEdge</string>
|
||||
<string name="classification_app_name">EasyEdge</string>
|
||||
<string name="facedet_app_name">EasyEdge</string>
|
||||
<string name="segmentation_app_name">EasyEdge</string>
|
||||
<string name="voice_assistant_app_name">voice assistant</string>
|
||||
<string name="super_resolution_app_name">Super Resolution</string>
|
||||
<string name="detection_app_name">FastDeploy Detection</string>
|
||||
<string name="ocr_app_name">FastDeploy OCR</string>
|
||||
<string name="classification_app_name">FastDeploy Classification</string>
|
||||
<string name="facedet_app_name">FastDeploy Face Detection</string>
|
||||
<string name="segmentation_app_name">FastDeploy Segmentation</string>
|
||||
<string name="voice_assistant_app_name">FastDeploy Voice Assistant</string>
|
||||
<string name="super_resolution_app_name">FastDeploy Super Resolution</string>
|
||||
<string name="uie_app_name">FastDeploy UIE</string>
|
||||
<string name="start_ui_activity">开始使用</string>
|
||||
<!-- Keys for PreferenceScreen -->
|
||||
<string name="CHOOSE_PRE_INSTALLED_MODEL_KEY">CHOOSE_INSTALLED_MODEL_KEY</string>
|
||||
@@ -44,6 +45,7 @@
|
||||
<string name="KEYPOINT_DETECTION_MODEL_DIR_DEFAULT">models/PP_TinyPose_128x96_infer</string>
|
||||
<string name="VOICE_ASSISTANT_MODEL_DIR_DEFAULT">models</string>
|
||||
<string name="SUPER_RESOLUTION_MODEL_DIR_DEFAULT">models</string>
|
||||
<string name="UIE_MODEL_DIR_DEFAULT">models/uie-nano</string>
|
||||
<!-- Other resources values-->
|
||||
<string name="action_bar_take_photo">拍照识别</string>
|
||||
<string name="action_bar_realtime">实时识别</string>
|
||||
@@ -56,4 +58,9 @@
|
||||
<string name="operation_confidence_control">阈值控制</string>
|
||||
<string name="operation_retry">重新识别</string>
|
||||
<string name="operation_save">保存结果</string>
|
||||
<!-- NLP Text values -->
|
||||
<string name="UIE_SCHEMA_HINT">请输入需要的信息模式,如: 时间,选手,赛事名称</string>
|
||||
<string name="UIE_SCHEMA_DEFAULT">时间, 选手, 赛事名称</string>
|
||||
<string name="UIE_INPUT_TEXTS_HINT">请输入需要分析的文本,如:2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌!</string>
|
||||
<string name="UIE_INPUT_TEXTS_DEFAULT">2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌!</string>
|
||||
</resources>
|
||||
|
||||
37
java/android/app/src/main/res/xml/uie_settings.xml
Normal file
37
java/android/app/src/main/res/xml/uie_settings.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListPreference
|
||||
android:defaultValue="@string/VOICE_ASSISTANT_MODEL_DIR_DEFAULT"
|
||||
android:key="@string/CHOOSE_PRE_INSTALLED_MODEL_KEY"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="Choose Pre-Installed Models" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="@string/UIE_MODEL_DIR_DEFAULT"
|
||||
android:key="@string/MODEL_DIR_KEY"
|
||||
android:title="Model Dir" />
|
||||
<ListPreference
|
||||
android:defaultValue="@string/CPU_THREAD_NUM_DEFAULT"
|
||||
android:entries="@array/cpu_thread_num_entries"
|
||||
android:entryValues="@array/cpu_thread_num_values"
|
||||
android:key="@string/CPU_THREAD_NUM_KEY"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="CPU Thread Num" />
|
||||
<ListPreference
|
||||
android:defaultValue="@string/CPU_POWER_MODE_DEFAULT"
|
||||
android:entries="@array/cpu_power_mode_entries"
|
||||
android:entryValues="@array/cpu_power_mode_values"
|
||||
android:key="@string/CPU_POWER_MODE_KEY"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="CPU Power Mode" />
|
||||
<ListPreference
|
||||
android:defaultValue="@string/ENABLE_LITE_FP16_MODE_DEFAULT"
|
||||
android:entries="@array/enable_lite_fp16_mode_entries"
|
||||
android:entryValues="@array/enable_lite_fp16_mode_values"
|
||||
android:key="@string/ENABLE_LITE_FP16_MODE_KEY"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="Enable Lite FP16" />
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user