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

use same parser to parse cli and gui arguments #179

Merged
merged 1 commit into from
Sep 12, 2022
Merged

use same parser to parse cli and gui arguments #179

merged 1 commit into from
Sep 12, 2022

Conversation

Freed-Wu
Copy link
Contributor

fix #175

❯ time pix2tex -h
usage: pix2tex [-h] [-t TEMPERATURE] [-c CONFIG] [-m CHECKPOINT] [--no-cuda] [--no-resize] [-s] [-f FILE] [-k] [--gui] [--gnome]

options:
  -h, --help            show this help message and exit
  -t TEMPERATURE, --temperature TEMPERATURE
                        Softmax sampling frequency
  -c CONFIG, --config CONFIG
                        path to config file
  -m CHECKPOINT, --checkpoint CHECKPOINT
                        path to weights file
  --no-cuda             Compute on CPU
  --no-resize           Resize the image beforehand
  -s, --show            Show the rendered predicted latex code (cli only)
  -f FILE, --file FILE  Predict LaTeX code from image file instead of clipboard (cli only)
  -k, --katex           Render the latex code in the browser (cli only)
  --gui                 Use GUI (gui only)
  --gnome               Use gnome-screenshot to capture screenshot (gui only)
pix2tex -h  0.03s user 0.01s system 99% cpu 0.041 total

I use same parser to parse cli and gui arguments. Only --gui or --gnome or
the name is pix2tex_gui or latexocr, it will use gui.

name = os.path.split(sys.argv[0])[-1]
if arguments.gui or arguments.gnome or name in ['pix2tex_gui', 'latexocr']:
    from .gui import main
else:
    from .cli import main

And now you can:

❯ python -m pix2tex -h
usage: __main__.py [-h] [-t TEMPERATURE] [-c CONFIG] [-m CHECKPOINT] [--no-cuda] [--no-resize] [-s] [-f FILE] [-k] [--gui] [--gnome]

options:
  -h, --help            show this help message and exit
  -t TEMPERATURE, --temperature TEMPERATURE
                        Softmax sampling frequency
  -c CONFIG, --config CONFIG
                        path to config file
  -m CHECKPOINT, --checkpoint CHECKPOINT
                        path to weights file
  --no-cuda             Compute on CPU
  --no-resize           Resize the image beforehand
  -s, --show            Show the rendered predicted latex code (cli only)
  -f FILE, --file FILE  Predict LaTeX code from image file instead of clipboard (cli only)
  -k, --katex           Render the latex code in the browser (cli only)
  --gui                 Use GUI (gui only)
  --gnome               Use gnome-screenshot to capture screenshot (gui only)

or

❯ pix2tex/__main__.py -h
usage: __main__.py [-h] [-t TEMPERATURE] [-c CONFIG] [-m CHECKPOINT] [--no-cuda] [--no-resize] [-s] [-f FILE] [-k] [--gui] [--gnome]

options:
  -h, --help            show this help message and exit
  -t TEMPERATURE, --temperature TEMPERATURE
                        Softmax sampling frequency
  -c CONFIG, --config CONFIG
                        path to config file
  -m CHECKPOINT, --checkpoint CHECKPOINT
                        path to weights file
  --no-cuda             Compute on CPU
  --no-resize           Resize the image beforehand
  -s, --show            Show the rendered predicted latex code (cli only)
  -f FILE, --file FILE  Predict LaTeX code from image file instead of clipboard (cli only)
  -k, --katex           Render the latex code in the browser (cli only)
  --gui                 Use GUI (gui only)
  --gnome               Use gnome-screenshot to capture screenshot (gui only)

@lukas-blecher lukas-blecher added the enhancement New feature or request label Sep 12, 2022
@lukas-blecher lukas-blecher merged commit 30c519d into lukas-blecher:main Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] reduce the time of pix2tex -h
2 participants