-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_server.py
41 lines (36 loc) · 1.01 KB
/
web_server.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
#web_server.py
#
#Web interface for summarization
#
#Written by Andrew Arpasi
from flask import Flask
from flask import request
from flask import Response
from url_summarize import URLSummarize
import json
import re
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello Tet!"
@app.route("/articleSummarize/", methods=['POST','OPTIONS'])
def summarize():
rawStr = str(request.stream.read())
rawStr = rawStr.replace("b'","")
rawStr = rawStr.replace("\\r\\n","")
rawStr = rawStr[:-1]
data = json.loads(rawStr)
print(data)
url = data['url']
length = int(data['length'])
urlsum = URLSummarize(url)
info = {}
info['metadata'] = urlsum.metadata()
info['summary'] = urlsum.summarize_article(length)
resultJSON = json.dumps(info, ensure_ascii=False)
response = Response(resultJSON,content_type="application/json")
response.headers.add('Access-Control-Allow-Origin', '*')
return response
if __name__ == "__main__":
app.run(host='0.0.0.0')
app.debug = True