Spaces:
Sleeping
Sleeping
abhishekrs4
commited on
Commit
•
6f8d5c0
1
Parent(s):
77b575f
updated script to send post requests
Browse files- test_post_request.py +20 -11
test_post_request.py
CHANGED
@@ -5,7 +5,8 @@ import argparse
|
|
5 |
import numpy as np
|
6 |
from sklearn.model_selection import train_test_split
|
7 |
|
8 |
-
from modeling.
|
|
|
9 |
|
10 |
class NumpyEncoder(json.JSONEncoder):
|
11 |
def default(self, obj):
|
@@ -13,18 +14,19 @@ class NumpyEncoder(json.JSONEncoder):
|
|
13 |
return obj.tolist()
|
14 |
return json.JSONEncoder.default(self, obj)
|
15 |
|
16 |
-
def send_post_reqest(ARGS):
|
17 |
-
df_csv = read_csv_file(ARGS.file_csv)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
print(X_test.shape)
|
23 |
|
24 |
url = "https://abhishekrs4-ml-water-potability.hf.space/predict"
|
25 |
# the endpoint of the post request
|
26 |
|
27 |
-
headers = {
|
28 |
# additional headers to indicate the content type of the post request
|
29 |
|
30 |
# perform 20 post requests
|
@@ -37,6 +39,7 @@ def send_post_reqest(ARGS):
|
|
37 |
# print(f"{type(json.loads(result.text))} \n")
|
38 |
return
|
39 |
|
|
|
40 |
def main():
|
41 |
file_csv = "dataset/water_potability.csv"
|
42 |
num_requests = 20
|
@@ -45,15 +48,21 @@ def main():
|
|
45 |
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
46 |
)
|
47 |
|
48 |
-
parser.add_argument(
|
49 |
-
type=str, help="full path to dataset csv file"
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
ARGS, unparsed = parser.parse_known_args()
|
54 |
send_post_reqest(ARGS)
|
55 |
|
56 |
return
|
57 |
|
|
|
58 |
if __name__ == "__main__":
|
59 |
main()
|
|
|
5 |
import numpy as np
|
6 |
from sklearn.model_selection import train_test_split
|
7 |
|
8 |
+
from modeling.data_utils import WaterPotabilityDataLoader
|
9 |
+
|
10 |
|
11 |
class NumpyEncoder(json.JSONEncoder):
|
12 |
def default(self, obj):
|
|
|
14 |
return obj.tolist()
|
15 |
return json.JSONEncoder.default(self, obj)
|
16 |
|
|
|
|
|
17 |
|
18 |
+
def send_post_reqest(ARGS):
|
19 |
+
water_pot_dataset = WaterPotabilityDataLoader(ARGS.file_csv)
|
20 |
+
water_pot_dataset.read_csv_file()
|
21 |
+
water_pot_dataset.split_data()
|
22 |
+
list_cols = water_pot_dataset.df_csv.columns[:-1]
|
23 |
+
X_test, Y_test = water_pot_dataset.get_data_from_data_frame(which_set="test")
|
24 |
print(X_test.shape)
|
25 |
|
26 |
url = "https://abhishekrs4-ml-water-potability.hf.space/predict"
|
27 |
# the endpoint of the post request
|
28 |
|
29 |
+
headers = {"Content-type": "application/json"}
|
30 |
# additional headers to indicate the content type of the post request
|
31 |
|
32 |
# perform 20 post requests
|
|
|
39 |
# print(f"{type(json.loads(result.text))} \n")
|
40 |
return
|
41 |
|
42 |
+
|
43 |
def main():
|
44 |
file_csv = "dataset/water_potability.csv"
|
45 |
num_requests = 20
|
|
|
48 |
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
49 |
)
|
50 |
|
51 |
+
parser.add_argument(
|
52 |
+
"--file_csv", default=file_csv, type=str, help="full path to dataset csv file"
|
53 |
+
)
|
54 |
+
parser.add_argument(
|
55 |
+
"--num_requests",
|
56 |
+
default=num_requests,
|
57 |
+
type=int,
|
58 |
+
help="number of post requests to send",
|
59 |
+
)
|
60 |
|
61 |
ARGS, unparsed = parser.parse_known_args()
|
62 |
send_post_reqest(ARGS)
|
63 |
|
64 |
return
|
65 |
|
66 |
+
|
67 |
if __name__ == "__main__":
|
68 |
main()
|