/
harassdectectGCPServerV2.py
92 lines (56 loc) · 1.95 KB
/
harassdectectGCPServerV2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import json
import datetime
import sys
from flask import Flask, request, redirect
from flask import make_response
from flask import jsonify
from flask_cors import CORS
import requests
import io
import hashlib
app = Flask(__name__)
CORS(app)
@app.route("/classifyGCP", methods=['POST'])
def classify_serve2():
"""Respond to incoming calls with a brief message."""
##resp = "Ok"
os.system ('$env:GOOGLE_APPLICATION_CREDENTIALS="F:\data\hackprinceton\gc.json"')
req_data = request.get_json()
text = req_data["text"]
author = req_data["author"]
print (" i received " + text)
print (" from " + author)
combotext = author + "|" + text
signature = hashlib.md5(combotext.encode('utf-8')).hexdigest()
print (signature)
##shortcode = signature[:10]
commandline = 'python predictMLv3.py "' + text +'" aiot-fit-xlab TCN3380722269616129492 '
print (commandline)
os.system(commandline)
with open("class.txt") as fp:
line = fp.readline()
cls = line.strip()
with open("confidence.txt") as fp:
line = fp.readline()
con = line.strip()
url = "http://10.24.148.214:3000"
payload = '{"name": "' + signature +'"}'
headers = {
'Content-Type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
injson = json.loads(response.text)
out_r = {}
out_r["status"] = "ok"
out_r["class"] = cls
out_r["confidence"] = con
out_r["transid"] = injson["data"]["id"]
out_r["blockid"] = injson["data"]["blockId"]
response = make_response(json.dumps(out_r))
response.headers['content-type'] = 'application/json'
return response
if __name__ == "__main__":
app.run(debug=True, port = 8002)
##app.run(debug=True, host = '169.62.204.155', port = 8001)