File size: 1,288 Bytes
711e3f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import io
import json
import argparse
import sys


# 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='Object detection 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))

    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:]))