-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
43 lines (29 loc) · 1.18 KB
/
main.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
'''
Runs a flask service for exposing the APIs.
Uses classes detailed in summarizer.py for summarization methods.
'''
from flask import Flask, render_template, request, flash, url_for, jsonify
from summarizer import *
from errorCheck import *
def errorDetect(text):
ec = errorCheck(text)
return ec.CheckInput()
app = Flask(__name__)
#change the file path to path of embedding file.
word_vector_file = '/home/pk/Downloads/crawl-300d-2M.magnitude'
s = Summarizer(word_vector_file)
@app.route('/summarize', methods=['POST'])
def summarize():
req_data = request.get_json()
text = req_data['text']
number_of_sentences = req_data['num']
errorStatus = errorDetect(text)
print(errorStatus)
if errorStatus == False:
summarized_text = ".\n".join(s.summarize(text, number_of_sentences)) #stitching the returned sentences together.
td = {'outputtext' : summarized_text, 'error': "None"}
return jsonify(td)
else:
return jsonify({'outputtext':'None','error':errorStatus})
if __name__ == '__main__':
app.run(host='0.0.0.0', port = 6000, debug=True) #change the port number here if a different port is to be used for running thie service.