Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

servicerequest.py 1.6 KB

You have to be logged in to leave a comment. Sign In
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  1. from typing import Tuple
  2. import json
  3. import keras
  4. import numpy as np
  5. import requests
  6. from src.prepare_data import get_data
  7. #SERVICE_URL = "http://127.0.0.1:3000/predict"
  8. # aws endpoint
  9. SERVICE_URL = "https://libobddgz8.execute-api.us-west-1.amazonaws.com/predict"
  10. def calculate_loss(reconstructions,data,type_loss):
  11. if type_loss=="mse":
  12. train_loss = keras.losses.mse(reconstructions, data)
  13. return train_loss
  14. elif type_loss=="mae":
  15. train_loss = keras.losses.mae(reconstructions, data)
  16. return train_loss
  17. def sample_random_ecg_data_point() -> Tuple[np.ndarray, np.ndarray]:
  18. test_data, test_labels = get_data('ecg_data','X_test.pickle'),get_data('ecg_data','y_test.pickle')
  19. random_index = np.random.randint(0, len(test_data),size=10)
  20. random_test_data = test_data[random_index]
  21. print(random_test_data.shape)
  22. if len(random_index)==1:
  23. random_test_data = np.expand_dims(random_test_data, 0)
  24. print(random_test_data.shape)
  25. return random_test_data, test_labels[random_index]
  26. def make_request_to_bento_service(
  27. service_url: str, input_array: np.ndarray
  28. ) -> str:
  29. serialized_input_data = json.dumps(input_array.tolist())
  30. response = requests.post(
  31. service_url,
  32. data=serialized_input_data,
  33. headers={"content-type": "application/json"}
  34. )
  35. return response.text
  36. def main():
  37. input_data, expected_output = sample_random_ecg_data_point()
  38. prediction = make_request_to_bento_service(SERVICE_URL, input_data)
  39. print(f"prediction: {prediction}")
  40. print(f"Expected output: {expected_output.astype(int)}")
  41. if __name__ == "__main__":
  42. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...