-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (56 loc) · 1.92 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template, request, jsonify
import json
from src.boardgen import Boardgen
from src.prediction import Predictor
from src.computer import Computer
app = Flask(__name__)
@app.route('/', methods=["POST", "GET"])
def index():
"""
Homepage for the website.
Create a random board.
"""
board = Boardgen("static/data/codenames_words").board
board.insert(0, {"difficulty": "easy",
"invalid_guesses": []
})
return render_template('html/page.html', board=board)
@app.route("/update", methods=["POST"])
def update():
"""
Update the page with the details from the current board
"""
board = json.loads(request.data)
return render_template('html/page.html', board=board)
@app.route("/computer_turn", methods=["POST"])
def computer_turn():
"""
Get a series of computer moves
"""
board = json.loads(request.data)
sequence = Computer(board).generate_computer_sequence()
json_sequence = jsonify(sequence=sequence)
return json_sequence
@app.route("/clue", methods=["POST"])
def clue():
"""
Generate a clue
"""
board = json.loads(request.data)
predictor = Predictor(relevant_words_path='static/data/relevant_words',
relevant_vectors_path='static/data/relevant_vectors',
board=board[1:],
invalid_guesses=set(board[0]['invalid_guesses']),
threshold=0.45)
_clue, clue_score, targets = predictor.run()
clue_details = jsonify(clue=_clue, targets=targets)
return clue_details
@app.route("/instructions", methods=["GET"])
def instructions():
"""
Render the dialog box containing the instructions
"""
return render_template('html/instructions.html')
if __name__ == '__main__':
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run(host='127.0.0.1', port=8080, debug=True)