-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
54 lines (43 loc) · 1.26 KB
/
main.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
from flask import (
Flask,
jsonify,
render_template,
request
)
import os
import subprocess
import struct
carpeta_actual = os.getcwd()
carpeta_static = carpeta_actual + "/templates/static"
app = Flask(__name__, static_folder=carpeta_static)
@app.route('/')
def index():
return render_template('index.html')
@app.route("/backpropagation", methods=['POST'])
def backpropagation():
response = {"answer": "ERROR"}
try:
matrix = request.get_json()['matriz']
with open('cmake-build-debug/matrix.bin', 'wb') as file:
rows = len(matrix)
columns = len(matrix[0])
file.write(struct.pack('ii', rows, columns))
for f in matrix:
for element in f:
file.write(struct.pack('i', element))
result = subprocess.run(
["./cmake-build-debug/inference"],
text=True,
capture_output=True
)
print(result)
if result.returncode != 0:
raise IOError("Return Code is not 0")
else:
response["answer"] = result.stdout
except Exception as e:
print(e)
response["answer"] = "ERROR"
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True, port=5000)