-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathClient.py
54 lines (40 loc) · 1.89 KB
/
Client.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
############################################################################################
#
# Project: Peter Moss Acute Myeloid & Lymphoblastic Leukemia AI Research Project
# Repository: ALL Detection System 2019
# Project: Chatbot
#
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
# Contributors:
# Title: Client Class
# Description: Sends requests to the ALL Detection System 2019 Chatbot.
# License: MIT License
# Last Modified: 2020-07-16
#
# Example Usage:
#
# $ python3 Client.py "What is the Peter Moss Acute Lymphoblastic Leukemia Detection System?"
#
################################################################################################################
import sys, time, string, requests, json
from Classes.Helpers import Helpers
class Client():
""" ALL Detection System 2019 Chatbot Client Class
Sends requests to the ALL Detection System 2019 Chatbot.
"""
def __init__(self):
""" Initializes the Chatbot Client class. """
self.Helpers = Helpers()
self.LogFile = self.Helpers.setLogFile(self.Helpers.confs["System"]["Logs"]+"Client/")
self.apiUrl = "http://" + self.Helpers.confs["System"]["IP"] + ":" + str(self.Helpers.confs["System"]["Port"])+"/infer"
self.headers = {"content-type": 'application/json'}
self.Helpers.logMessage(self.LogFile, "CLIENT", "INFO", "Client Ready")
if __name__ == "__main__":
Client = Client()
data = {"query": str(sys.argv[1])}
Client.Helpers.logMessage(Client.LogFile, "CLIENT",
"INFO", "Sending string for classification...")
response = requests.post(Client.apiUrl, data=json.dumps(data),
headers=Client.headers)
Client.Helpers.logMessage(Client.LogFile, "CLIENT",
"OK", "Response: "+str(response.text))