-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
34 lines (27 loc) · 1.06 KB
/
test.py
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
import requests
import json
import os
import time
fraud_path = "./train-samples/Fraud"
not_fraud_path = "./train-samples/NotFraud"
fraud_files = [os.path.join(fraud_path,f) for f in os.listdir(fraud_path)]
not_fraud_files = [os.path.join(not_fraud_path,f) for f in os.listdir(not_fraud_path)]
print("Testing fraud files from: {}".format(fraud_path))
start_time = time.time()
tn = 0
# test fraud audio files
for file in fraud_files:
files = {'sample': open(file,'rb')}
values = {}
response = requests.post("http://0.0.0.0:8080/test-sample",files=files, data=values)
tn += 1 if json.loads(response.text)["result"]==1 else 0
tp = 0
# test non fraud audio files
for file in not_fraud_files:
files = {'sample': open(file,'rb')}
values = {}
response = requests.post("http://0.0.0.0:8080/test-sample",files=files, data=values)
tp += 1 if json.loads(response.text)["result"]==0 else 0
print("Test done!")
print("Fraud: {}/{} NonFraud: {}/{}".format(tn,len(fraud_files),tp,len(not_fraud_files)))
print("Elapsed time:{} sec".format(time.time()-start_time))