File size: 1,370 Bytes
9ecca49
 
 
 
 
711e3f5
 
9ecca49
711e3f5
 
 
 
 
 
 
 
 
 
9ecca49
711e3f5
9ecca49
 
 
 
 
711e3f5
 
 
 
 
 
 
 
 
9ecca49
 
711e3f5
 
9ecca49
711e3f5
 
 
 
9ecca49
711e3f5
 
 
 
 
9ecca49
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
"""
IRIS classification - command line inference via API
"""

import sys
import json
import argparse
import requests


# Default examples
# api_url = "http://localhost:8080/2015-03-31/functions/function/invocations"


def arg_parser():
    """Parse arguments"""

    # Create an ArgumentParser object
    parser = argparse.ArgumentParser(description="IRIS classification inference via API call")
    # Add arguments
    parser.add_argument(
        "-u", "--url", type=str, help="URL to the server (with endpoint location)", required=True
    )
    parser.add_argument("-d", "--data", type=str, help="Input data", required=True)
    parser.add_argument("-v", "--verbose", action="store_true", help="Increase output verbosity")
    return parser


def main(args=None):
    """Main function"""

    args = arg_parser().parse_args(args)
    # Use the arguments
    if args.verbose:
        print(f"Input data: {args.data}")
        print(f"Input data type: {type(args.data)}")

    # Send request to API
    response = requests.post(args.url, json=json.loads(args.data), timeout=60)

    if response.status_code == 200:
        # Process the response
        processed_data = json.loads(response.content)
        print("processed_data", processed_data)
    else:
        print(f"Error: {response.status_code}")


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))