Audiveris / audiveris

Latest generation of Audiveris OMR engine
https://audiveris.github.io/audiveris
GNU Affero General Public License v3.0
1.51k stars 225 forks source link

-batch headless not functioning properly #749

Closed hguan-dev closed 1 month ago

hguan-dev commented 1 month ago

After fixing the previous issue of accessing a working build, I'm having difficulties running Audiveris in headless mode through the CLI. As is, my local version is also using -batch as part of the CLI command, but a GUI still ends up popping up (although the processing works fine). After porting this to a Ubuntu AWS EC2 instance, this problem results in some Java Exceptions as it seems the -batch command still does not work properly for me.

Really appreciate any help!

Here is the code in the python script I am using to put together the command:

command = [AUDIVERIS_PATH, '-batch', '-output', output_dir, input_filepath]

And here is the Audiveris output in the terminal:

DEBUG:root:Contents of output directory after running Audiveris: ['93c83f614bc0b1cf1d7a30d942e83237-20240808T2318.log', '93c83f614bc0b1cf1d7a30d942e83237.omr']

stderr: DEBUG:root:Export output: INFO  []                       CLI 281  | CLI args: [-export, /home/ubuntu/omr-api/output/e90d3bb9-ccc5-4eb4-a391-de9630d4b1e9/93c83f614bc0b1cf1d7a30d942e83237.omr, -output, /home/ubuntu/omr-api/output/e90d3bb9-ccc5-4eb4-a391-de9630d4b1e9/93c83f614bc0b1cf1d7a30d942e83237.mxl]
INFO  []              TesseractOCR 116  | TESSDATA_PREFIX value: /home/ubuntu/tessdata
INFO  []              TesseractOCR 241  | OCR folder: /home/ubuntu/tessdata
INFO  []                      Main 402  | Environment:
- Audiveris:    5.4-alpha:988233aee
- OS:           Linux 6.8.0-1009-aws
- Architecture: amd64
- Java VM:      OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)
- OCR Engine:   Tesseract OCR, version 5.3.1
INFO  []             AliasPatterns 134  | Alias patterns: [(IMSLP[0-9]*)-.*]

stderr: DEBUG:root:Export errors: Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
    at org.jdesktop.application.ResourceMap.<clinit>(ResourceMap.java:1354)
    at org.jdesktop.application.ResourceManager.createResourceMap(ResourceManager.java:468)
    at org.jdesktop.application.ResourceManager.createResourceMapChain(ResourceManager.java:151)
    at org.jdesktop.application.ResourceManager.createResourceMapChain(ResourceManager.java:150)
    at org.jdesktop.application.ResourceManager.getApplicationResourceMap(ResourceManager.java:170)
    at org.jdesktop.application.ResourceManager.getResourceMap(ResourceManager.java:307)
    at org.jdesktop.application.ApplicationContext.getResourceMap(ApplicationContext.java:206)
    at org.jdesktop.application.Application.create(Application.java:250)
    at org.jdesktop.application.Application$1.run(Application.java:185)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.awt.HeadlessException: 
No X11 DISPLAY variable was set,
or no headful library support was found,
but this program performed an operation which requires it,

    at java.desktop/sun.awt.HeadlessToolkit.getMenuShortcutKeyMask(HeadlessToolkit.java:135)
    at org.jdesktop.application.ResourceMap$KeyStrokeStringConverter.<clinit>(ResourceMap.java:1511)
    ... 22 more

DEBUG:root:Contents of output directory after exporting: ['93c83f614bc0b1cf1d7a30d942e83237-20240808T2318.log', '93c83f614bc0b1cf1d7a30d942e83237.omr']
ERROR:root:No MusicXML file generated
DEBUG:root:Audiveris process completed.
hbitteur commented 1 month ago

Here is the code in the python script I am using to put together the command: command = [AUDIVERIS_PATH, '-batch', '-output', output_dir, input_filepath]

And here is the Audiveris output in the terminal: stderr: DEBUG:root:Export output: INFO [] CLI 281 | CLI args: [-export, /home/ubuntu/omr-api/output/e90d3bb9-ccc5-4eb4-a391-de9630d4b1e9/93c83f614bc0b1cf1d7a30d942e83237.omr, -output, /home/ubuntu/omr-api/output/e90d3bb9-ccc5-4eb4-a391-de9630d4b1e9/93c83f614bc0b1cf1d7a30d942e83237.mxl]

Not yet answering your problem with a headless configuration, but just a remark about the CLI arguments.

The CLI arguments, as printed by your Audiveris run, look like (I'm putting one argument per line for readability): -export /path/to/some.omr -output /path/to/some.mxl

1/ These CLI arguments don't seem to correspond to the python command (the -batch argument is gone?) 2/ The -output argument should introduce a folder, not an .mxl file

hbitteur commented 1 month ago

Perhaps a stupid question.

If you don't use the -batch CLI argument, Audiveris is by default launched in the interactive mode. Which will be non-compatible with your headless environment. Perhaps your problem is as simple as that?

hguan-dev commented 1 month ago

Fixed the issue, had separate endpoints of upload and transcribe and found the error. Thanks for your help!