forked from axenov/LocalBertSummarization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflaskController.py
More file actions
executable file
·78 lines (64 loc) · 2.14 KB
/
Copy pathflaskController.py
File metadata and controls
executable file
·78 lines (64 loc) · 2.14 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
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
73
74
75
76
77
78
#!/usr/bin/python3
from flask import Flask, flash, request, redirect, url_for
from nif.annotation import *
from flask_cors import CORS
import re
import os
import shutil
from werkzeug.utils import secure_filename
import zipfile
import sys
import dill as pickle
import codecs
from summarizer import AbstractiveSummarizer
"""
then to start run:
export FLASK_APP=flaskController.py
export FLASK_DEBUG=1 (optional, to reload upon changes automatically)
python -m flask run
example calls:
curl -X GET localhost:5000/welcome
"""
app = Flask(__name__)
app.secret_key = "super secret key"
CORS(app)
'''
Headers:
Accept: text/turtle
Content-Type: text/turtle OR text/plain
Language: en OR de
Method: bert OR conv
Extract: true OR false
'''
@app.route('/srv-summarize/analyzeText', methods=['POST'])
def summarize():
if request.method == 'POST':
cType = request.headers["Content-Type"]
accept = request.headers["Accept"]
kvargs_summ ={}
if 'Extract' in request.headers:
kvargs_summ['extract'] = True if request.headers['Extract'] == 'true' else False
if 'Language' in request.headers:
kvargs_summ['language'] = request.headers['Language']
if 'Method' in request.headers:
kvargs_summ['method'] = request.headers['Method']
data=request.stream.read().decode("utf-8")
if accept == 'text/turtle':
pass
else:
return 'ERROR: the Accept header '+accept+' is not supported!'
if cType == 'text/plain':
uri_prefix="http://lynx-project.eu/res/"+str(uuid.uuid4())
d = NIFDocument.from_text(data, uri_prefix)
elif cType == 'text/turtle':
d = NIFDocument.parse_rdf(data, format='turtle')
else:
return 'ERROR: the contentType header '+cType+' is not supported!'
service = AbstractiveSummarizer(**kvargs_summ)
summ = service.analyzeNIF(d)
return summ.serialize(format="ttl")
else:
return 'ERROR, only POST method allowed.'
if __name__ == '__main__':
port = int(os.environ.get('PORT',5000))
app.run(host='localhost', port=port, debug=True)