jhj0517 commited on
Commit
f79aae9
·
1 Parent(s): f6d527b

Refactor bool to `str2bool` in CLI

Browse files
Files changed (2) hide show
  1. app.py +5 -4
  2. modules/utils/cli_manager.py +12 -0
app.py CHANGED
@@ -12,6 +12,7 @@ from modules.whisper.faster_whisper_inference import FasterWhisperInference
12
  from modules.whisper.insanely_fast_whisper_inference import InsanelyFastWhisperInference
13
  from modules.translation.nllb_inference import NLLBInference
14
  from modules.ui.htmls import *
 
15
  from modules.utils.youtube_manager import get_ytmetas
16
  from modules.translation.deepl_api import DeepLAPI
17
  from modules.whisper.whisper_parameter import *
@@ -377,16 +378,16 @@ class App:
377
  parser = argparse.ArgumentParser()
378
  parser.add_argument('--whisper_type', type=str, default="faster-whisper",
379
  help='A type of the whisper implementation between: ["whisper", "faster-whisper", "insanely-fast-whisper"]')
380
- parser.add_argument('--share', type=bool, default=False, nargs='?', const=True, help='Gradio share value')
381
  parser.add_argument('--server_name', type=str, default=None, help='Gradio server host')
382
  parser.add_argument('--server_port', type=int, default=None, help='Gradio server port')
383
  parser.add_argument('--root_path', type=str, default=None, help='Gradio root path')
384
  parser.add_argument('--username', type=str, default=None, help='Gradio authentication username')
385
  parser.add_argument('--password', type=str, default=None, help='Gradio authentication password')
386
  parser.add_argument('--theme', type=str, default=None, help='Gradio Blocks theme')
387
- parser.add_argument('--colab', type=bool, default=False, nargs='?', const=True, help='Is colab user or not')
388
- parser.add_argument('--api_open', type=bool, default=False, nargs='?', const=True, help='Enable api or not in Gradio')
389
- parser.add_argument('--inbrowser', type=bool, default=True, nargs='?', const=True, help='Whether to automatically start Gradio app or not')
390
  parser.add_argument('--whisper_model_dir', type=str, default=WHISPER_MODELS_DIR,
391
  help='Directory path of the whisper model')
392
  parser.add_argument('--faster_whisper_model_dir', type=str, default=FASTER_WHISPER_MODELS_DIR,
 
12
  from modules.whisper.insanely_fast_whisper_inference import InsanelyFastWhisperInference
13
  from modules.translation.nllb_inference import NLLBInference
14
  from modules.ui.htmls import *
15
+ from modules.utils.cli_manager import str2bool
16
  from modules.utils.youtube_manager import get_ytmetas
17
  from modules.translation.deepl_api import DeepLAPI
18
  from modules.whisper.whisper_parameter import *
 
378
  parser = argparse.ArgumentParser()
379
  parser.add_argument('--whisper_type', type=str, default="faster-whisper",
380
  help='A type of the whisper implementation between: ["whisper", "faster-whisper", "insanely-fast-whisper"]')
381
+ parser.add_argument('--share', type=str2bool, default=False, nargs='?', const=True, help='Gradio share value')
382
  parser.add_argument('--server_name', type=str, default=None, help='Gradio server host')
383
  parser.add_argument('--server_port', type=int, default=None, help='Gradio server port')
384
  parser.add_argument('--root_path', type=str, default=None, help='Gradio root path')
385
  parser.add_argument('--username', type=str, default=None, help='Gradio authentication username')
386
  parser.add_argument('--password', type=str, default=None, help='Gradio authentication password')
387
  parser.add_argument('--theme', type=str, default=None, help='Gradio Blocks theme')
388
+ parser.add_argument('--colab', type=str2bool, default=False, nargs='?', const=True, help='Is colab user or not')
389
+ parser.add_argument('--api_open', type=str2bool, default=False, nargs='?', const=True, help='Enable api or not in Gradio')
390
+ parser.add_argument('--inbrowser', type=str2bool, default=True, nargs='?', const=True, help='Whether to automatically start Gradio app or not')
391
  parser.add_argument('--whisper_model_dir', type=str, default=WHISPER_MODELS_DIR,
392
  help='Directory path of the whisper model')
393
  parser.add_argument('--faster_whisper_model_dir', type=str, default=FASTER_WHISPER_MODELS_DIR,
modules/utils/cli_manager.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+
4
+ def str2bool(v):
5
+ if isinstance(v, bool):
6
+ return v
7
+ if v.lower() in ('yes', 'true', 't', 'y', '1'):
8
+ return True
9
+ elif v.lower() in ('no', 'false', 'f', 'n', '0'):
10
+ return False
11
+ else:
12
+ raise argparse.ArgumentTypeError('Boolean value expected.')