B4J Question 1st PyBridge try: alfa-test

peacemaker

Expert
Licensed User
Longtime User
Hi, All and @Erel ,

Just tried for the first time your PyBridge draft. B4J 10.0
Compiling at line:
Dim correctClassesNames As Map = jo.InitializeStatic("anywheresoftware.b4a.randomaccessfile.RandomAccessFile").GetField("correctedClasses")
gives the error:
Waiting for debugger to connect...
Program started.
Error occurred on line: 18 (PyComm)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:486)
at b4j.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:875)
at b4j.example.b4xpagesmanager._showpage(b4xpagesmanager.java:354)
at b4j.example.b4xpagesmanager._addpage(b4xpagesmanager.java:175)
at b4j.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:189)
at b4j.example.b4xpagesmanager._initialize(b4xpagesmanager.java:125)
at b4j.example.main._appstart(main.java:85)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.start(main.java:38)
at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:134)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:81)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 28 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:115)
... 30 more
Caused by: java.lang.RuntimeException: Field: correctedClasses not found in: anywheresoftware.b4a.randomaccessfile.RandomAccessFile
at anywheresoftware.b4j.object.JavaObject$FieldCache.getField(JavaObject.java:307)
at anywheresoftware.b4j.object.JavaObject.GetField(JavaObject.java:182)
at b4j.example.pycomm._initialize(pycomm.java:108)
at b4j.example.pybridge._start(pybridge.java:181)
at b4j.example.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:130)
at b4j.example.b4xmainpage._b4xpage_created(b4xmainpage.java:84)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 32 more
Just alfa-test...
Any updates in jRandomAccessFile lib?
 

Attachments

  • TempDownload.png
    TempDownload.png
    17.8 KB · Views: 150
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Thanks.
PyBridge is not yet on beta stage
Sure, let it be public alfa-test.

It's started, but not for too long:

Waiting for debugger to connect...
Program started.
(b4j) Server is listening on port: 61756
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
(out) starting PyBridge v0.1
watchdog set to 60 seconds
Connecting to port: 61756
(b4j) connected
(err) thon Error (ModuleNotFoundError) - Method: module.exec: No module named 'easyocr'
(err) thon Error (AttributeError) - Method: function.__call__: 'Exception' object has no attribute 'readtext'
(b4j) Python Error (AttributeError) - Method: function.__call__: 'Exception' object has no attribute 'readtext'
Error occurred on line: 120 (PyWrapper)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.pywrapper._getvalue(pywrapper.java:141)
at b4j.example.pyocr$ResumableSub_ReadText.resume(pyocr.java:112)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:156)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1118)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.RuntimeException: Python Error (AttributeError) - Method: function.__call__: 'Exception' object has no attribute 'readtext'
at b4j.example.pywrapper.raiseError(pywrapper.java:616)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 28 more
Error is just after opening a picture.
My Python path is:
"D:\Programs\winpy\WPy64-31241\python-3.12.4.amd64\python.exe"
60 symbols, maybe critical...
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
For ref:
1) 5+ GB of Python are to be installed...
2) If under Win - after start "WinPython Terminal.exe" - it needs to install the EasyOCR https://www.jaided.ai/easyocr/install/ Python library with its dependencies (OpenCV and others)...

Technologies now are oversized...
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, thanks, Erel. After EasyOCR installation - it's started OK and started to load some more :)
Downoaded at 100%, but it needs to add sub "py_disconnected":

(out) Progress: |?????????????????????????????????????????????????-| 99.8% Complete
(out) Progress: |?????????????????????????????????????????????????-| 99.8% Complete
(out) Progress: |?????????????????????????????????????????????????-| 99.9% Complete
(out) Progress: |?????????????????????????????????????????????????-| 99.9% Complete
(out) Progress: |??????????????????????????????????????????????????| 100.0% Complete
(b4j) disconnected
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: Sub py_disconnected was not found.
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:522)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:493)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:567)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub py_disconnected was not found.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:513)
... 9 more
Caused by: java.lang.Exception: Sub py_disconnected was not found.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:118)
... 11 more
(b4j) Process completed. ExitCode: 1
And started to work !
But endless work with small-sized picture cannot be interrupted, had to close and restart.

Next try with big picture with non-EN texts (but OCR was inited for "en"):
Waiting for debugger to connect...
Program started.
(b4j) Server is listening on port: 62096
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
(out) starting PyBridge v0.1
watchdog set to 60 seconds
Connecting to port: 62096
(b4j) connected
(err) Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU.
(err) thon Error (AttributeError) - Method: function.__call__: 'NoneType' object has no attribute 'shape'
(b4j) Python Error (AttributeError) - Method: function.__call__: 'NoneType' object has no attribute 'shape'
Error occurred on line: 120 (PyWrapper)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.pywrapper._getvalue(pywrapper.java:141)
at b4j.example.pyocr$ResumableSub_ReadText.resume(pyocr.java:112)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:156)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1118)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.RuntimeException: Python Error (AttributeError) - Method: function.__call__: 'NoneType' object has no attribute 'shape'
at b4j.example.pywrapper.raiseError(pywrapper.java:616)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 28 more

For each language to recognize - the new OCR reader is again downloaded...
 

Attachments

  • 1738243645095.png
    1738243645095.png
    180.1 KB · Views: 104
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Well done! You can see the downloaded models in the Objects folder under the ~ folder.

Have you installed torch with cuda enabled?

You can verify it with:
B4X:
Wait For (IsCudaAvailable) Complete (Available As Boolean)
Log("cuda: " & Available)

Private Sub IsCudaAvailable As ResumableSub
    Wait For (Py.ImportLib.ImportModule("torch").GetField("cuda").Run("is_available", Null).Fetch) Complete (Res As PyWrapper)
    Return Res.Value
End Sub
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Non-EN pictures are also recognized, even if to twice scale picture down by area (400 x 200 px). But single-letter words are missed.
Small non-readable picture is fastly stopped to process, without error.
1738245825019.png


Other errors are to be processed somehow.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Note: OpenCV used cannot read non-en file names:

Waiting for debugger to connect...
Program started.
(b4j) Server is listening on port: 62502
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
(out) starting PyBridge v0.1
watchdog set to 60 seconds
Connecting to port: 62502
(b4j) connected
(err) Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU.
cuda: false
(err) [ WARN:[email protected]] global loadsave.cpp:268 cv::findDecoder imread_('C:\1\�����������_viber_2024-03-16_15-02-45-662.jpg'): can't open/read file: check file path/integrity
(err) [ WARN:[email protected]] global loadsave.cpp:268 cv::findDecoder imread_('R:\����������.jpg'): can't open/read file: check file path/integrity
(err) thon Error (AttributeError) - Method: function.__call__: 'NoneType' object has no attribute 'shape'
(b4j) Python Error (AttributeError) - Method: function.__call__: 'NoneType' object has no attribute 'shape'
Error occurred on line: 120 (PyWrapper)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.pywrapper._getvalue(pywrapper.java:137)
at b4j.example.pyocr$ResumableSub_ReadText.resume(pyocr.java:112)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)

How to catch these errors ? Or make non-fatal somehow...
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Yes, thanks, Erel. After EasyOCR installation - it's started OK and started to load some more :)
Downoaded at 100%,
1738253050005.png

nevers downloading the model...

1) winpython (7z extracted ~2GB)
2) I ve pip(ed) pytorch
3) also jaided pip(ed)

all about ~5GB

...some times copying py_bridge.zip at roaming folder... but nothing more..
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
"Ready" status ?
Many errors crashed running.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Path to python.exe in the code?
"Objects\~" folder with downloaded model (-s) ?
 
Upvote 0
Top