MCPcopy Create free account
hub / github.com/DataScienceHamburg/PyTorchUltimateMaterial / predict

Function predict

600_ModelDeployment/app_iris.py:15–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13
14@app.route('/predict', methods = ['GET', 'POST'])
15def 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
33if __name__ == '__main__':

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected