-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
60 lines (48 loc) · 1.76 KB
/
application.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
# -*- coding: utf-8 -*-
import html
import os
from time import time
from flask import Flask, request, send_from_directory, render_template, make_response
from rq import Queue
from worker import conn
from subject import Subject
app = Flask(__name__)
q = Queue(connection=conn)
@app.route('/')
def send_index():
return send_from_directory('static', 'index.html')
@app.route('/<path:path>')
def send_static(path):
return send_from_directory('static', path)
@app.route('/synthesis', methods=['POST'])
def getSynthesis():
try:
id_str = (request.form['subject']+str(time())).replace(' ', '-')
if request.form.get('wikipedia'):
useWikipedia = True
else:
useWikipedia = False
subject = Subject(request.form['subject'], summaryLength=int(
request.form['lines']), useWikipedia=useWikipedia)
q.enqueue(subject.build, job_id=id_str, timeout=600)
except Exception as e:
return '<h1>Error</h1>' + str(e)
return render_template('working.html', url='/status/' + id_str)
@app.route('/status/<job_id>')
def job_status(job_id):
job = q.fetch_job(job_id)
if job.result is None:
response = make_response('no')
else:
subjectText = render_template(
'done.html', sections=job.result.sections, title=job.result.wikiPage.title, sourceMap=job.result.sourceMap)
if job.is_failed:
subjectText = '<h1>Error!</h1>'
response = make_response(subjectText)
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
return response
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5003))
app.run(host='0.0.0.0', port=port)
print('running on localhost:5003')