gagan3012 commited on
Commit
df9a42c
·
1 Parent(s): 3966dd0

Create cli.py

Browse files
Files changed (1) hide show
  1. src/cli/cli.py +64 -0
src/cli/cli.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import subprocess
4
+ import sys
5
+
6
+ arg_parser = argparse.ArgumentParser(description="T5 Summarisation Using Pytorch Lightning",
7
+ prog="t5s")
8
+ # Command choice
9
+ command_subparser = arg_parser.add_subparsers(dest="command", help="command (refer commands section in documentation)")
10
+
11
+ parser_req = command_subparser.add_parser('requirements', help='Install Python Dependencies.')
12
+
13
+ parser_dirs = command_subparser.add_parser('dirs', help='Create directories that are ignored by git but required for '
14
+ 'the project')
15
+
16
+ parser_push = command_subparser.add_parser('push', help='Upload Data to default DVC remote')
17
+
18
+ parser_pull = command_subparser.add_parser('pull', help="Download Data from default DVC remote")
19
+
20
+ parser_run = command_subparser.add_parser('run', help="run the DVC pipeline - recompute any modified outputs such as "
21
+ "processed data or trained models")
22
+
23
+ parser_visualize = command_subparser.add_parser('visualize', help="run the visualization using Streamlit")
24
+
25
+ parser_push_to_hf_hub = command_subparser.add_parser('push_to_hf_hub', help="push the trained model to HF model hub")
26
+
27
+ parser_lint = command_subparser.add_parser('lint', help=" Lint using flake8")
28
+
29
+ parser_clone = command_subparser.add_parser('clone', help="Clone the T5 summarisation repo")
30
+
31
+
32
+ class Run(object):
33
+ def __init__(self, arguments: dict):
34
+ self.arguments = arguments
35
+
36
+ def execute(self):
37
+ arguments = self.arguments
38
+ print(f"arguments passed: {arguments['command']}")
39
+ # os.chdir('../')
40
+ retval = os.getcwd()
41
+ print(retval)
42
+ list_files = subprocess.run(["make", arguments["command"]])
43
+ return list_files.returncode
44
+
45
+
46
+ def parse_args(args):
47
+ arguments = vars(arg_parser.parse_args(args=args or ["--help"]))
48
+ return arguments
49
+
50
+
51
+ def main(args=None):
52
+ if args is None:
53
+ args = sys.argv[1:]
54
+ parsed_args = parse_args(args=args)
55
+ try:
56
+ result = Run(arguments=parsed_args).execute()
57
+ except Exception as e:
58
+ print(str(e))
59
+ result = 1
60
+ sys.exit(result)
61
+
62
+
63
+ if __name__ == "__main__":
64
+ main()