File size: 2,794 Bytes
df9a42c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
785bfbd
df9a42c
 
 
 
 
 
 
 
 
 
 
 
 
 
eb71b0f
38cf30c
 
 
a598c32
d846f4a
38cf30c
d483016
 
 
 
 
 
763abdb
ba6e3c5
763abdb
df9a42c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import os
import subprocess
import sys

arg_parser = argparse.ArgumentParser(description="T5 Summarisation Using Pytorch Lightning",
                                     prog="t5s")
# Command choice
command_subparser = arg_parser.add_subparsers(dest="command", help="command (refer commands section in documentation)")

parser_req = command_subparser.add_parser('requirements', help='Install Python Dependencies.')

parser_dirs = command_subparser.add_parser('dirs', help='Create directories that are ignored by git but required for '
                                                        'the project')

parser_push = command_subparser.add_parser('push', help='Upload Data to default DVC remote')

parser_pull = command_subparser.add_parser('pull', help="Download Data from default DVC remote")

parser_run = command_subparser.add_parser('run', help="run the DVC pipeline - recompute any modified outputs such as "
                                                      "processed data or trained models")

parser_visualize = command_subparser.add_parser('visualize', help="run the visualization using Streamlit")

parser_upload = command_subparser.add_parser('upload', help="push the trained model to HF model hub")

parser_lint = command_subparser.add_parser('lint', help=" Lint using flake8")

parser_clone = command_subparser.add_parser('clone', help="Clone the T5 summarisation repo")


class Run(object):
    def __init__(self, arguments: dict):
        self.arguments = arguments

    def execute(self):
        arguments = self.arguments
        print(f"arguments passed: {arguments['command']}")
        # os.chdir('../')
        cmd = ['requirements', 'dirs', 'push', 'pull', 'run', 'visualize', 'upload', 'lint']
        if arguments['command'] == "clone":
            list_files = subprocess.run(["git", "clone", "https://dagshub.com/gagan3012/summarization.git"])
            os.chdir('./summarization/')
            retval = os.getcwd()
            print(retval)
            return list_files.returncode
        elif arguments['command'] in cmd:
            os.chdir('./summarization/')
            retval = os.getcwd()
            print(retval)
            list_files = subprocess.run(["make", arguments["command"]])
            return list_files.returncode
        else:
            print("Command not supported")
            raise Exception


def parse_args(args):
    arguments = vars(arg_parser.parse_args(args=args or ["--help"]))
    return arguments


def main(args=None):
    if args is None:
        args = sys.argv[1:]
    parsed_args = parse_args(args=args)
    try:
        result = Run(arguments=parsed_args).execute()
    except Exception as e:
        print(str(e))
        result = 1
    sys.exit(result)


if __name__ == "__main__":
    main()