Skip to content

Commit

Permalink
release: official release v1.3.5 after fix some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwg committed Mar 26, 2024
1 parent a8610aa commit a24dec5
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ prebuilts/toolchain/emsdk/
prebuilts/toolchain/*.zip
prebuilts/toolchain/*.xz
prebuilts/toolchain/*.gz

core/
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public class CDEUtils {
public static final int ASR_MODE_BECHMARK = 2; // asr peformance benchamrk
public static final int ASR_MODE_TRANSCRIPTION_RECORD = 3; // transcription + audio record

//keep sync with kantv_asr.h
public static final int BECHMARK_ASR = 0;
public static final int BECHMARK_MEMCPY = 1;
public static final int BECHMARK_MULMAT = 2;
public static final int BECHMARK_FULL = 3; //looks good on Xiaomi 14 after optimized by build optimization

private static int mASRMode = ASR_MODE_NORMAL;

private static AtomicBoolean mCouldExitApp = new AtomicBoolean(true);
Expand Down Expand Up @@ -3892,6 +3898,25 @@ public void onClick(DialogInterface dialog, int which) {
}


public static String getBenchmarkDesc(int benchmarkIndex) {
switch (benchmarkIndex) {
case BECHMARK_FULL:
return "GGML whisper_encode";

case BECHMARK_MEMCPY:
return "GGML memcopy";

case BECHMARK_MULMAT:
return "GGML matrix multipy";

case BECHMARK_ASR:
return "GGML ASR inference";
}

return "unknown";
}


public static String getGGMLModeString(int ggmlModeType) {
switch (ggmlModeType) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
package com.cdeos.kantv.ui.fragment;

import static org.ggml.whispercpp.whispercpp.WHISPER_ASR_MODE_BECHMARK;
import static org.ggml.whispercpp.whispercpp.WHISPER_ASR_MODE_NORMAL;
import static org.ggml.whispercpp.whispercpp.WHISPER_ASR_MODE_PRESURETEST;
import static cdeos.media.player.CDEUtils.BECHMARK_ASR;
import static cdeos.media.player.KANTVEvent.KANTV_INFO_ASR_FINALIZE;
import static cdeos.media.player.KANTVEvent.KANTV_INFO_ASR_STOP;

Expand Down Expand Up @@ -92,12 +91,6 @@ public class ASRResearchFragment extends BaseMvpFragment<ASRResearchPresenter> i

Button _btnBenchmark;

//keep sync with kantv_asr.h
private static final int BECHMARK_ASR = 0;
private static final int BECHMARK_MEMCPY = 1;
private static final int BECHMARK_MULMAT = 2;
private static final int BECHMARK_FULL = 3; //looks good on Xiaomi 14 after optimized by build optimization

private int nThreadCounts = 1;
private int benchmarkIndex = 0;
private String strModeName = "tiny";
Expand Down Expand Up @@ -286,7 +279,7 @@ public void onNothingSelected(AdapterView<?> parent) {

_btnBenchmark.setOnClickListener(v -> {
CDELog.j(TAG, "strModeName:" + strModeName);
CDELog.j(TAG, "exec ggml benchmark: type: " + getBenchmarkDesc(benchmarkIndex) + ", threads:" + nThreadCounts + ", model:" + strModeName);
CDELog.j(TAG, "exec ggml benchmark: type: " + CDEUtils.getBenchmarkDesc(benchmarkIndex) + ", threads:" + nThreadCounts + ", model:" + strModeName);

String selectModeFileName = "ggml-" + strModeName + ".bin";
String selectModelFilePath = CDEUtils.getDataPath() + selectModeFileName;
Expand All @@ -299,7 +292,7 @@ public void onNothingSelected(AdapterView<?> parent) {
File sampleFile = new File(CDEUtils.getDataPath() + ggmlSampleFileName);

if (!selectModeFile.exists() || (!sampleFile.exists())) {
showMsgBox(mActivity, "pls check whether GGML's model file and sample file(jfk.wav) exist in /sdcard/kantv/");
CDEUtils.showMsgBox(mActivity, "pls check whether GGML's model file and sample file(jfk.wav) exist in /sdcard/kantv/");
return;
}
ggmlModelFileName = selectModeFileName;
Expand All @@ -311,7 +304,7 @@ public void onNothingSelected(AdapterView<?> parent) {

isBenchmarking.set(true);

startUIBuffering(mContext.getString(R.string.ggml_benchmark_updating) + "(" + getBenchmarkDesc(benchmarkIndex) + ")");
startUIBuffering(mContext.getString(R.string.ggml_benchmark_updating) + "(" + CDEUtils.getBenchmarkDesc(benchmarkIndex) + ")");

Toast.makeText(mContext, mContext.getString(R.string.ggml_benchmark_start), Toast.LENGTH_LONG).show();

Expand Down Expand Up @@ -359,7 +352,7 @@ public void run() {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
String benchmarkTip = getBenchmarkDesc(benchmarkIndex) + "(model: " + strModeName
String benchmarkTip = CDEUtils.getBenchmarkDesc(benchmarkIndex) + "(model: " + strModeName
+ " ,threads: " + nThreadCounts
+ " ) cost " + duration + " milliseconds";
benchmarkTip += "\n";
Expand Down Expand Up @@ -539,7 +532,7 @@ private void initKANTVMgr() {
} catch (KANTVException ex) {
String errorMsg = "An exception was thrown because:\n" + " " + ex.getMessage();
CDELog.j(TAG, "error occurred: " + errorMsg);
showMsgBox(mActivity, errorMsg);
CDEUtils.showMsgBox(mActivity, errorMsg);
ex.printStackTrace();
}
}
Expand All @@ -566,35 +559,7 @@ public void release() {
}


private void showMsgBox(Context context, String message) {
AlertDialog dialog = new AlertDialog.Builder(context).create();
dialog.setMessage(message);
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

}
});
dialog.show();
}


private String getBenchmarkDesc(int benchmarkIndex) {
switch (benchmarkIndex) {
case BECHMARK_FULL:
return "GGML whisper_encode";

case BECHMARK_MEMCPY:
return "GGML memcopy";

case BECHMARK_MULMAT:
return "GGML matrix multipy";

case BECHMARK_ASR:
return "GGML ASR inference";
}

return "unknown";
}

private void displayFileStatus(String sampleFilePath, String modelFilePath) {
_txtGGMLStatus.setText("");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Copyright (c) 2024- KanTV Author
*
* 03-26-2024, weiguo, this is a skeleton/initial UI for study llama.cpp on Android phone
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -50,8 +52,6 @@
import com.cdeos.kantv.mvp.view.LLMResearchView;
import com.cdeos.kantv.utils.Settings;

import org.ggml.whispercpp.whispercpp;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -73,7 +73,7 @@


public class LLMResearchFragment extends BaseMvpFragment<LLMResearchPresenter> implements LLMResearchView {
@BindView(R.id.ggmlLayout)
@BindView(R.id.ggmlLayoutLLM)
LinearLayout layout;

private static final String TAG = LLMResearchFragment.class.getName();
Expand All @@ -83,11 +83,6 @@ public class LLMResearchFragment extends BaseMvpFragment<LLMResearchPresenter> i

Button _btnBenchmark;

//keep sync with kantv_asr.h
private static final int BECHMARK_ASR = 0;
private static final int BECHMARK_MEMCPY = 1;
private static final int BECHMARK_MULMAT = 2;
private static final int BECHMARK_FULL = 3; //looks good on Xiaomi 14 after optimized by build optimization

private int nThreadCounts = 1;
private int benchmarkIndex = 0;
Expand All @@ -101,6 +96,8 @@ public class LLMResearchFragment extends BaseMvpFragment<LLMResearchPresenter> i
private AtomicBoolean isBenchmarking = new AtomicBoolean(false);
private ProgressDialog mProgressDialog;

// https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF
// https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf
private String ggmlModelFileName = "llama-2-7b-chat.Q4_K_M.gguf"; //4.08 GB

private Context mContext;
Expand Down Expand Up @@ -138,9 +135,8 @@ public void initView() {
Resources res = mActivity.getResources();

_txtLLMInfo = (TextView) mActivity.findViewById(R.id.llmInfo);
_txtGGMLInfo = (TextView) mActivity.findViewById(R.id.ggmlInfo);
_txtGGMLStatus = (TextView) mActivity.findViewById(R.id.ggmlStatus);
_btnBenchmark = (Button) mActivity.findViewById(R.id.btnBenchmark);
_txtGGMLInfo = (TextView) mActivity.findViewById(R.id.ggmlInfoLLM);
_txtGGMLStatus = (TextView) mActivity.findViewById(R.id.ggmlStatusLLM);

_txtLLMInfo.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
displayFileStatus(CDEUtils.getDataPath() + ggmlModelFileName);
Expand Down Expand Up @@ -181,16 +177,6 @@ public void onStop() {
super.onStop();
}

private void showMsgBox(Context context, String message) {
AlertDialog dialog = new AlertDialog.Builder(context).create();
dialog.setMessage(message);
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

}
});
dialog.show();
}


private void displayFileStatus(String modelFilePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@ public void setModeName(String engineName, String modelA, String modelB) {

CDELog.j(TAG, "engineName: " + engineName + " file:" + modelA);
CDELog.j(TAG, "modelName: " + engineName + " file:" + modelB);
/*
localModleFileA = CDEUtils.getDataPath(mContext) + modelFileNameA;
localModleFileB = CDEUtils.getDataPath(mContext) + modelFileNameB;
*/

// /sdcardk/kantv/jfk.wav
// /sdcard/kantv/ggml-xxx.bin
localModleFileA = CDEUtils.getDataPath() + modelFileNameA;
localModleFileB = CDEUtils.getDataPath() + modelFileNameB;

// http://www.cde-os.com/kantv/ggml/jfk.wav, available
remoteModleFileA = "http://" + CDEUtils.getKANTVMasterServer() + "/kantv/" + engineName + "/" + modelFileNameA;
remoteModleFileB = "http://" + CDEUtils.getKANTVMasterServer() + "/kantv/" + engineName + "/" + modelFileNameB;

// http://www.cde-os.com/kantv/ggml/ggml-***.bin, not available since 03-22-2024
// remoteModleFileB = "http://" + CDEUtils.getKANTVMasterServer() + "/kantv/" + engineName + "/" + modelFileNameB;
// replace with upstream url since 03-22-2024
// the GGML whispercpp model could be found at https://huggingface.co/ggerganov/whisper.cpp/tree/main
remoteModleFileB = "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/" + modelFileNameB;

CDELog.j(TAG, "remote model url:" + remoteModleFileB);
}


Expand Down
19 changes: 13 additions & 6 deletions cdeosplayer/kantv/src/main/res/layout/fragment_llm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,48 @@
android:orientation="vertical">

<TextView
android:id="@+id/pageInfo"
android:id="@+id/pageInfoLLM"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="LLM(Large Language Model) research(by GGML's llama.cpp)" />

<LinearLayout
android:id="@+id/ggmlLayout"
android:id="@+id/ggmlLayoutLLM"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/ggmlLogo"
android:id="@+id/ggmlLogoLLM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/llamacpp_logo" />

<TextView
android:id="@+id/ggmlInfo"
android:id="@+id/ggmlInfoLLM"
android:layout_width="match_parent"
android:layout_height="200dp" />

<TextView
android:id="@+id/ggmlStatus"
android:id="@+id/ggmlStatusLLM"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:text=" " />


</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/llmInfo"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_height="100dp"
android:layout_marginTop="5dp" />

</LinearLayout>
Expand Down
4 changes: 2 additions & 2 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Project KanTV was almost/completely done by myself since 05-2021 and NO IPR conc

I know very very very little about real/hard-core AI tech because I majored in economics at university and all computer-related knowledge was fully self-taught by library(I'm very poor at that time and I couldn't afford a PC). of course, I have not studied advanced mathematics or signal theory.

The original author of whisper.cpp and llama.cpp is a real great genius programmer, but I'm just an ordinary Linux/Android system software programmer but I'm good at multimedia/streaming media tech.
In short, I'm just an ordinary Linux/Android system software programmer(know something about iOS app development) but I'm good at streaming media tech and interested in study&practice AI tech in real-scenario on mobile device(Android or iOS).

<hr>

Expand All @@ -45,7 +45,7 @@ The source code of KanTV Android APP has been completely open source, and the so

One year later(on 03-23-2024), I read an article from <a href="https://changelog.com/podcast/532">https://changelog.com/podcast/532</a>

A few days ago, I didn't understand why Georgi Gerganov open source such a powerful whisper.cpp and all these iOS/Android app are free. After reading this article, I think I understand a little bit. I want to / have to say that Georgi Gerganov is a real great genius programmer. just my personal thoughts, this could/should/might NOT be happend in my country:
A few days ago, I didn't understand why Georgi Gerganov open source such a powerful whisper.cpp and all these iOS/Android app are free. After reading this article, I think I understand a little bit. I'd like to say that Georgi Gerganov is a real great genius programmer. just my personal thoughts, this could/should/might NOT be happend in my country:

<ul>
<li>
Expand Down
4 changes: 3 additions & 1 deletion external/whispercpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Copyright (c) 2024- KanTV Authors. All Rights Reserved.
# Copyright (c) 2024, zhou.weiguo(zhouwg2000@gmail.com)

# Copyright (c) 2024- KanTV Authors

# Description: build libwhispercpp.so for target Android

Expand Down
4 changes: 3 additions & 1 deletion external/whispercpp/build-android-jni-lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

# Copyright (c) 2024- KanTV Authors. All Rights Reserved.
# Copyright (c) 2024, zhou.weiguo(zhouwg2000@gmail.com)

# Copyright (c) 2024- KanTV Authors

# Description: build libwhispercpp.so for target Android
#
Expand Down
2 changes: 1 addition & 1 deletion external/whispercpp/diff-with-upstream-whispercpp.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright (c) 2024- KanTV Authors. All Rights Reserved.
# Copyright (c) 2024- KanTV Authors

# Description: check difference between local whisper.cpp and upstream whisper.cpp
#
Expand Down
2 changes: 1 addition & 1 deletion external/whispercpp/sync-with-upstream-whispercpp.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright (c) 2024- KanTV Authors. All Rights Reserved.
# Copyright (c) 2024- KanTV Authors

# Description: sync source code between local whisper.cpp and upstream whisper.cpp
#
Expand Down

0 comments on commit a24dec5

Please sign in to comment.