-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (46 loc) · 1.71 KB
/
app.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
from flask import Flask, Response, render_template
from flask_sqlalchemy import SQLAlchemy
from errors import errors
from cmap import CMAP
app = Flask(__name__)
app.register_blueprint(errors)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
app.app_context().push()
class Paper(db.Model):
title = db.Column(db.String(256), index=True)
tldr = db.Column(db.String(512), index=True)
year = db.Column(db.Integer, index=True)
score = db.Column(db.Float, index=True)
scores = db.Column(db.String(64), index=True)
keywords = db.Column(db.String(256), index=True)
authors = db.Column(db.String(256), index=True)
venue = db.Column(db.String(64), index=True)
id = db.Column(db.String(20))
url = db.Column(db.String(64), primary_key=True)
decision = db.Column(db.String(32), index=True)
def to_dict(self):
bgcolor = CMAP.get(self.decision, "#FFFFFF")
return {
'title': f'<a href="{self.url}">{self.title}</a>',
'tldr': self.tldr,
'year': self.year,
'keywords': self.keywords,
'score': self.score,
'scores': self.scores,
'venue': self.venue,
'authors': self.authors,
'decision': f'<span style="background-color:{bgcolor};">{self.decision}</span>',
}
# db.create_all()
@app.route("/")
def index():
return render_template('ajax_papers_table.html', title='OpenReview Explorer Plus')
@app.route('/api/data')
def data():
papers = [paper.to_dict() for paper in Paper.query]
return {'data': papers}
@app.route("/health")
def health():
return Response("OK", status=200)