-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
40 lines (29 loc) · 1 KB
/
server.py
File metadata and controls
40 lines (29 loc) · 1 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
from flask import Flask, render_template
from doc2vec import *
import sys
# Launch with
#
# gunicorn -D --threads 4 -b 0.0.0.0:5000 --access-logfile server.log --timeout 60 server:app glove.6B.300d.txt bbc
app = Flask(__name__)
@app.route("/")
def articles():
"""Show a list of article titles"""
return render_template("articles.html", articles = articles)
@app.route("/article/<topic>/<filename>")
def article(topic,filename):
"""
Show an article with relative path filename. Assumes the BBC structure of
topic/filename.txt so our URLs follow that.
"""
for a in articles:
if topic + "/" + filename == a[0]:
article = a
break
seealso = recommended(article, articles, 5)
return render_template("article.html", article = article, seealso = seealso)
# initialization
i = sys.argv.index('server:app')
glove_filename = sys.argv[i+1]
articles_dirname = sys.argv[i+2]
gloves = load_glove(glove_filename)
articles = load_articles(articles_dirname, gloves)