-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_the_model.py
61 lines (44 loc) · 1.63 KB
/
test_the_model.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 22 04:10:54 2021
@author: Ibrah
"""
import json
import time
import requests
# API endpoint
SERVER_URL = "http://localhost:8501/v1/models/TSA_model:predict"
# THRESHOLD
THRESHOLD = 0.625
def main():
"""Main"""
# Write down your sentence here
examples = [["Messi inserted the clutch gene in PSG. 2 last minute winners in 3 days. MY GOAT"],
["Feeling lonely tonight, why do I have to go through this ?"]]
# Create the request
inputs = list(examples)
predict_request = json.dumps({'instances': inputs})
# Send few requests to warm-up the model.
for _ in range(3):
response = requests.post(SERVER_URL, data=predict_request)
response.raise_for_status()
# Initialize the timer
print("\nSending request...")
timer = time.time()
# Send a request to the model
response = requests.post(SERVER_URL, data=predict_request)
response.raise_for_status()
# Calculate and display the elapsed time
timer = round(time.time() - timer, 2)
print(f"\nElapsed time: {timer}s")
# Get the response
predictions = response.json()['predictions']
print(f"\n\nExamples: {[example[0] for example in examples]} ")
print(f"\n\nPredictions: {predictions}")
# Loop through the results and assign a label
for prediction in predictions:
prediction[0] = "Positive" if prediction[0] > THRESHOLD else "Negative"
# Display results
print(f"\nOutput: {predictions}")
if __name__ == '__main__':
main()