Commit
•
4a88266
1
Parent(s):
e11580d
added script to send post request to the backend flask app
Browse files- test_post_request.py +49 -0
test_post_request.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import logging
|
3 |
+
import argparse
|
4 |
+
import requests
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
|
8 |
+
def send_image_post_request(ARGS: argparse.Namespace) -> None:
|
9 |
+
logging.basicConfig(level=logging.INFO)
|
10 |
+
list_test_images = os.listdir(ARGS.dir_test_images)
|
11 |
+
|
12 |
+
for file_image in list_test_images:
|
13 |
+
file_image = os.path.join(ARGS.dir_test_images, file_image)
|
14 |
+
files = {"image_file": (file_image, open(file_image, "rb"))}
|
15 |
+
|
16 |
+
# if the deployment is on local machine
|
17 |
+
# response = requests.post(
|
18 |
+
# "http://127.0.0.1:7860/predict",
|
19 |
+
# files=files,
|
20 |
+
# )
|
21 |
+
|
22 |
+
# if the deployment is on hugging face
|
23 |
+
response = requests.post(
|
24 |
+
"https://abhishekrs4-handwriting-recognition.hf.space/predict",
|
25 |
+
files=files,
|
26 |
+
)
|
27 |
+
|
28 |
+
logging.info(response.json())
|
29 |
+
return
|
30 |
+
|
31 |
+
|
32 |
+
def main() -> None:
|
33 |
+
dir_test_images = "./sample_test_images/"
|
34 |
+
parser = argparse.ArgumentParser(
|
35 |
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
36 |
+
)
|
37 |
+
parser.add_argument(
|
38 |
+
"--dir_test_images",
|
39 |
+
default=dir_test_images,
|
40 |
+
type=str,
|
41 |
+
help="full directory path to dataset containing test images",
|
42 |
+
)
|
43 |
+
ARGS, unparsed = parser.parse_known_args()
|
44 |
+
send_image_post_request(ARGS)
|
45 |
+
return
|
46 |
+
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
main()
|