()
| 13 | |
| 14 | @app.route('/predict', methods = ['GET', 'POST']) |
| 15 | def predict(): |
| 16 | if request.method == 'GET': |
| 17 | return 'Please use POST method' |
| 18 | if request.method == 'POST': |
| 19 | data = request.data.decode('utf-8') |
| 20 | dict_data = json.loads(data.replace("'", "\"")) |
| 21 | X = torch.tensor([dict_data["data"]]) |
| 22 | y_test_hat_softmax = model(X) |
| 23 | y_test_hat = torch.max(y_test_hat_softmax, 1) |
| 24 | y_test_cls = y_test_hat.indices.cpu().detach().numpy()[0] |
| 25 | cls_dict = { |
| 26 | 0: 'setosa', |
| 27 | 1: 'versicolor', |
| 28 | 2: 'virginica' |
| 29 | } |
| 30 | return f"Your flower belongs to class {cls_dict[y_test_cls]}" |
| 31 | |
| 32 | |
| 33 | if __name__ == '__main__': |
nothing calls this directly
no outgoing calls
no test coverage detected