Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support CLI arguments for passing the configuration files #201

Open
Udayraj123 opened this issue Aug 1, 2024 · 15 comments
Open

Comments

@Udayraj123
Copy link
Owner

Udayraj123 commented Aug 1, 2024

Is your feature request related to a problem? Please describe.
We should support CLI arguments for passing the configuration files such as template.json, config.json and evaluation.json

Describe the solution you'd like
We can use these names for the args

python3 main.py [<existing args>] [--templateFile <path>] [--evaluationFile <path>] [--configFile <path>]

Describe alternatives you've considered
As of now we need to make sure the file exists in the --inputDir folder.

Additional context
This would be a small change for beginners to understand how directory parsing works in OMRChecker currently.

@VidhuSarwal
Copy link

VidhuSarwal commented Aug 3, 2024

Hi, I am interested in doing this, Rather I have started work on it, Since this my first time doing something like this, will take some time, but so far have figured out basic plan.

  1. Add three new arguments, --templateFile, --evaluationFile, --configFile in parse_args of main.py
  2. Modify the process_dir function in entry.py so that it takes the new attributes passed by entry_point_for_args to entry_point in entry.py. Will modify it such that for Eg. If a template_file argument is provided, use it instead of looking for the file. Else, Raise an exception.

@VidhuSarwal
Copy link

Ok, So I am able to pass config.json and template.json file via CLI, but the evaluationFile for example, sheet1.jpg, on passing it throws the error
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 176: character maps to <undefined>

The traceback for it is below.
File "C:\Users\Users\Documents\OMR\OMRChecker\main.py", line 120, in <module> entry_point_for_args(args) File "C:\Users\Users\Documents\OMR\OMRChecker\main.py", line 112, in entry_point_for_args entry_point( File "C:\Users\Users\Documents\OMR\OMRChecker\src\entry.py", line 36, in entry_point return process_dir(input_dir, curr_dir, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Users\Documents\OMR\OMRChecker\src\entry.py", line 113, in process_dir evaluation_config = EvaluationConfig(curr_dir, evaluation_path, template, tuning_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Users\Documents\OMR\OMRChecker\src\evaluation.py", line 193, in __init__ evaluation_json = open_evaluation_with_validation(evaluation_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Users\Documents\OMR\OMRChecker\src\utils\parsing.py", line 66, in open_evaluation_with_validation user_evaluation_config = load_json(evaluation_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Users\Documents\OMR\OMRChecker\src\utils\file.py", line 15, in load_json loaded = json.load(f, **rest) ^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation\Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 293, in load return loads(fp.read(), ^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation\Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input, self.errors, decoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 176: character maps to <undefined>

However, The code works perfectly if I place the jpg file in inputs folder and config and template are passed through CLI.

@palash018
Copy link
Contributor

palash018 commented Aug 3, 2024

@VidhuSarwal, could you try it with other samples as well and check if they produce the same error? . Please join Discord for further discussion.

@Udayraj123
Copy link
Owner Author

@VidhuSarwal possible to discuss over discord? I've created a thread here

https://discord.com/channels/590134763784896514/1269271619398930455/1269271648318652466

Also would like to get your introduction over there :)

@VidhuSarwal
Copy link

VidhuSarwal commented Aug 4, 2024

Yeah sure! I will join the discord server.

Edit : The link is not working, I am getting the below error.

image

@Udayraj123
Copy link
Owner Author

@VidhuSarwal please the check the link from Readme.

@Usool-Data-Science
Copy link

@Udayraj123 It seems this issue is still open, please assign it to me so I can implement the required feature.

@Udayraj123
Copy link
Owner Author

No problem, @Usool-Data-Science, please share an approach you'd like to try here. I'll assign you the issue

@Usool-Data-Science
Copy link

We will extend the main.py script to handle additional command-line arguments using the popular argparse module, simplifying argument parsing and management. This means we will have a couple of functions
First, we define the parser with argparse.ArgumentParser() and specify all possible arguments using the add_argument() method. We indicate each argument's type and whether it is optional or required. When the script runs, parser.parse_args() processes the command-line inputs and stores them in an args object. We can then access and use these arguments within our script as needed.

@Udayraj123
Copy link
Owner Author

Assigned you the ticket 👍
Apart from above you should also check on how the directory parsing works currently to find an appropriate place to override the files.

@Usool-Data-Science
Copy link

Usool-Data-Science commented Sep 16, 2024

@Udayraj123 Do you know how I can use this application from within my WSL, I have installed all dependencies but when I tried to run the main.py I kept getting this error despite all my efforts to make it work.
image

I am running the WSL from within Windows 11 with the following config:

Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04

@palash018
Copy link
Contributor

palash018 commented Sep 16, 2024

@Usool-Data-Science The issue arises because the screen wasn't detected on WSL. I've pushed a fix for this in my branch in the utils/interaction.py file, allowing it to run properly on Container. You can check out the changes here: Commit f94fb6d.

this may also help WSL GUI

@Usool-Data-Science
Copy link

@palash018 yes mate, I am aware of that, I need help on how to direct it to use the windows screen instead

@VidhuSarwal
Copy link

Hey I was working on this issue, Almost done with it too. I didnt check github for some time. Am done with argument passing, currently debugging the issue with UTF-8 encoding in JSON.

@Usool-Data-Science
Copy link

@VidhuSarwal
Sorry mate I don't mean to belittle your effort, I thought you were busy with other stuff, you can go ahead and complete it then; However, if you need help kindly let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants