-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
72 lines (52 loc) · 2.12 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
72
from bottle import route, run, template, get, post, request
from bottle import static_file, redirect
from api import get_students, get_similar_docs, initialize_textrazor, get_top_entities
import logging
import sys
title = "#bettertogether"
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
textrazor_client = initialize_textrazor()
@route('/')
def welcome():
return template('welcome', title=title)
@get('/inputs')
def inputs():
info = {'title': title, 'students': get_students()}
return template('inputs', info)
@post('/plot')
def formhandler():
student = request.forms.get('student')
assignment = request.forms.get('assignment')
similar_docs = get_similar_docs(student, assignment)
if len(similar_docs) == 0:
redirect("/error/" + str(assignment) + '/' + student)
else:
info = {'student': student, 'assignment': assignment, 'similar_docs': similar_docs}
return template('plot', info)
@route('/compare/<assignment>/<student_1>/<student_2>')
def user_api(assignment, student_1, student_2):
entities_1 = get_top_entities(student_1, assignment, textrazor_client=textrazor_client)
entities_2 = get_top_entities(student_2, assignment, textrazor_client=textrazor_client)
info = {'assignment': assignment,
'student_1': student_1,
'entities_1': entities_1,
'file_1': '/pdfs/' + student_1 + ' - Assignment ' + assignment + '.pdf',
'student_2': student_2,
'entities_2': entities_2,
'file_2': '/pdfs/' + student_2 + ' - Assignment ' + assignment + '.pdf'}
return template('compare', info)
@route('/motivation')
def motivation():
return template('motivation', title=title)
@route('/error/<assignment>/<student>')
def error(assignment, student):
info = {'assignment': assignment, 'student': student}
return template('error', info)
@route('/static/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='static')
@route('/pdfs/<path>')
def server_static(path):
return static_file(path, root='pdfs')
if __name__ == '__main__':
run(host='0.0.0.0', port=8080)