-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
34 lines (25 loc) · 981 Bytes
/
server.py
File metadata and controls
34 lines (25 loc) · 981 Bytes
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
# Import libraries
import numpy as np
import pickle
from flask import Flask, request, jsonify
from tensorflow.keras.preprocessing.sequence import pad_sequences
from utils import clean
from model import decode_sequence, in_tokenizer
app = Flask(__name__)
@app.route('/api/summarize', methods=['POST'])
def summarize():
# Get the data from the POST request.
data = request.get_json(force=True)['text']
# Make prediction using model loaded from disk as per the data.
print("Review :",data)
data = clean(data,"inputs")
data = ' '.join(data)
inp_x = in_tokenizer.texts_to_sequences([data])
inp_x = pad_sequences(inp_x, maxlen=max_in_len, padding='post')
summary = decode_sequence(inp_x.reshape(1,max_in_len))
if 'eos' in summary :
summary=summary.replace('eos','')
print("\nPredicted summary:",summary);print("\n")
return jsonify(output)
if __name__ == '__main__':
app.run(port=5000, debug=True)