forked from adildsw/PreMaX
/
server.py
73 lines (49 loc) · 1.57 KB
/
server.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
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 19 12:59:06 2019
@author: AdilDSW
"""
import io
import os
import json
from flask import Flask, render_template, request, send_file
from generator import Generator
from predictor import Predictor
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/airpressure')
def airpressure():
return render_template('airpressure.html')
@app.route('/pump')
def pump():
return render_template('pump.html')
@app.route('/generate', methods=['GET'])
def generatorAPI():
model = request.args.get('model')
class_type = request.args.get('class_type')
genObj = Generator()
generated_data = genObj.generate(model, class_type)
output = io.BytesIO()
output.write(generated_data.encode('utf-8'))
output.seek(0)
return send_file(output, as_attachment=True,
attachment_filename="{}_generated.txt".format(model))
@app.route('/predict', methods=['GET'])
def predictorAPI():
model = request.args.get('model')
data = request.args.get('data')
preObj = Predictor()
prediction = preObj.predict(model, data)
return str(prediction)
if __name__ == "__main__":
config = {'ip': '127.0.0.1', 'port': '8888'}
if os.path.exists('config.json'):
with open('config.json') as config_file:
config = json.load(config_file)
app.debug = True
app.run(host=config['ip'], port=config['port'], use_reloader=False)