-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (38 loc) · 1.52 KB
/
app.py
File metadata and controls
42 lines (38 loc) · 1.52 KB
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
from flask import Flask, render_template, request
import honnet
import numpy as np
TIMES_SERVED = 0
app = Flask(__name__)
model = honnet.load()
TEAM_NAMES = ['Legion', 'Hellbourne']
@app.route('/', methods=['POST', 'GET'])
def index():
global TIMES_SERVED
legion = honnet.extract_hero_ids(request.args.get('legion'))
hellbourne = honnet.extract_hero_ids(request.args.get('hellbourne'))
print('Legion:', legion)
print('Hellbourne:', hellbourne)
match = honnet.to_match_dict(legion, hellbourne)
vector = honnet.vectorize_matches([match], include_Y=False)
prediction = model.predict(vector)
print('Prediction:', prediction)
TIMES_SERVED += 1
print('Times Served:', TIMES_SERVED)
return render_template(
'index.html',
legion=legion,
hellbourne=hellbourne,
legion_prob=round(100 * prediction[0][0,0], 2),
hellbourne_prob=round(100 * prediction[0][0,1], 2),
concede_prob=int(round(100 * prediction[1][0,0])),
lasting_minutes=int(round(prediction[2][0,0] / 60)),
heroes_id_dict=honnet.heroes_id_dict,
winner=TEAM_NAMES[np.argmax(prediction[0][0,:])],
loser=TEAM_NAMES[np.argmin(prediction[0][0,:])],
optimal_legion=honnet.optimal_hero_choice(model, match,
hellbourne_side=False),
optimal_hellbourne=honnet.optimal_hero_choice(model, match,
hellbourne_side=True)
)
if __name__ == '__main__':
app.run()