Share My Creation B4ML-Kit The Journey

B4ML-Kit - The Journey

There is a long back-story here, but I will simply describe
what I did without explaining why I chose to do certain
things in a certain way.

This is a proof of concept; hopefully, an inspiration to
someone accustomed to working with Android Studio
or Intellij IDEA (which is what AS uses anyway).

Code for ML-Kit is available as an AS project. I built
the OCR/Barcode/Face Recognition models, as well
as the Translation model. ML-Kit replaces ML vision
and ML-Kit Firebase models. There are (at least) 2
important effect: 1) Because ML vision is deprecated,
there is no new development, and 2) the new ML-Kit
adds languages to its OCR and Translation models
that were not available on-device previously.

It is now possible to extract text from a Chinese document,
for example, and translate it into, among others, English or
French, etc.

I wanted to do this using B4A.

Please review the attached images.

There are 2 apps involved: the ML-Kit model (which needs
to be modified and built) and a B4A "driver".

I chose some German and Chinese text from our forum and
translated them into English, French and Spanish.

Basically, what was involved was passing the text and source
and destination languages to ML-Kit as an intent for result.
On the ML-Kit side, I modified it to accept such an intent and
return the translation to the B4A caller. I also massaged
ML-Kit so that it would function normally if it wasn't launched
by an intent.

For the ML-Kit OCR model, I stripped all the garbage out so
that a scanned Chinese document could pass its result to
the Translation model (and to B4A).
 

Attachments

  • 1.png
    1.png
    39.5 KB · Views: 2,620
  • b4mlkit.png
    b4mlkit.png
    13.3 KB · Views: 610
  • de-en1.png
    de-en1.png
    39.2 KB · Views: 470
  • de-en2.png
    de-en2.png
    43.8 KB · Views: 798
  • de-fr1.png
    de-fr1.png
    38.8 KB · Views: 296
  • de-fr2.png
    de-fr2.png
    44.2 KB · Views: 269
  • zh-en1.png
    zh-en1.png
    38.1 KB · Views: 267
  • zh-en2.png
    zh-en2.png
    40.6 KB · Views: 249
  • zh-es1.png
    zh-es1.png
    38.6 KB · Views: 249
  • zh-es2.png
    zh-es2.png
    41.4 KB · Views: 308

josejad

Expert
Licensed User
Longtime User
Hi drgottjr:

I'm trying to test your app. It's not clear to me what to do with the "nl-translate-debug.apk". I've tried to install it but I just get a message "The app can't be installed".
When I try the filterout2.apk I don't get any download, and when I press the "GO" button, I get the error:
"An error has ocurred in
sub:main_button1_click (java line: 452)
java.lang.ClassCastException:
anywheresoftware.b4a.B4AUncaugException cannot be cast to java.lang.Exception"

Waiting for instructions :)

Samsung A10, Android 11
 

drgottjr

Expert
Licensed User
Longtime User
without the mlkit apk, there is basically nothing.
the b4a driver will certainly error out when it tries to run the intent. it sets the component which is not there.
it sets the component for the intent. in a release version, there
would/should be a test for the existence of the mlkit apk before
running the intent.

also, the driver downloads nothing. it simply shows how to
pass text to the translator and receive the translation back.
the mlkit app handles translating and downloading languages,
as needed. but if it won't install, then game over.

i was able to install the mlkit apk on 3 devices from their
respective download/files folder. on 1 device i had to set a
permission to allow the files folder to install apps. but that
doesn't seem to be the case for you as you were able to
install the driver apk. my devices are running android 12.
maybe there is an issue with the mlkit apk's target sdk and
a device running android 11 (although i would suspect you
can support sdk30.)

sorry for the hassle and thanks for trying.
 

drgottjr

Expert
Licensed User
Longtime User
as usual, you cannot get a straight answer from the internet (or your device) why an app cannot be installed. you just get the message.
and dozens of opinions.

you're welcome to try again and report anything new, but don't waste your weekend with it.
 

josejad

Expert
Licensed User
Longtime User
Hi drgottjr:

It's working now¡¡¡
Regarding the error, yesterday I installed the new version you sent me, and I think there were no error in your first version too.
It was my problem (I did it quickly and withOUT my glasses), so I got an error (with a dialog very different to the usual ones) but there was a small link under it: "Install it anyway".

So... I write in english and I get my translation into spanish, and viceversa¡¡¡¡
 

drgottjr

Expert
Licensed User
Longtime User
thanks for your patience
 

Attachments

  • ja.png
    ja.png
    41 KB · Views: 144

drgottjr

Expert
Licensed User
Longtime User
the apk was never posted because it was too big for
the forum. furthermore, google has not updated mlkit's
translation technology in the year since i first posted my
project (i don't think they're really very interested in mlkit;
they've basically incorporated all that technology into their
everyday applications). in addition, only 1 forum member
(now 2, including you) showed any interest, so i moved on.
it wasn't a library that you could do something useful with.
too bad you didn't pick up the thread a year ago...
 
Top