-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
45 lines (33 loc) · 1.38 KB
/
server.py
File metadata and controls
45 lines (33 loc) · 1.38 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
43
44
45
from flask import Flask, render_template, request
from lab1.src.identifiers import LanguageIdentifier
from lab2.src.engine import CorrectionEngine
identifier = LanguageIdentifier(statistics_dir='lab1/statistics')
correction_engine = CorrectionEngine(forms_file='lab2/forms/formy.txt')
app = Flask(__name__)
# TODO: change to websockets
@app.route("/lab1", methods=['POST', 'GET'])
@app.route("/", methods=['POST', 'GET'])
def lab1():
global identifier
ctx = {}
if request.method == 'POST':
statistics = []
text_to_identify = request.form['text_to_identify']
for n in range(2, 11):
distances, language = identifier.identify(text_to_identify, n)
statistics.append({'language': language, 'distances': distances})
ctx.update({'statistics': statistics, 'text_to_identify': text_to_identify})
return render_template('lab1.html', **ctx)
@app.route("/lab2", methods=['POST', 'GET'])
def lab2():
global correction_engine
ctx = {}
if request.method == 'POST':
text_to_correct = request.form['text_to_correct']
corrected_text = correction_engine.correct_text(text_to_correct)
ctx.update({'corrected_text': corrected_text, 'text_to_correct': text_to_correct})
return render_template('lab2.html', **ctx)
if __name__ == '__main__':
app.debug = True
app.run()
# app.run(host='0.0.0.0', port=80)