import pandas as pd import numpy as np import string import flask from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences from flask import Flask, request, jsonify, render_template import nltk import json from tensorflow.keras.models import load_model import tensorflow as tf model = load_model("_best_model_LSTM.hdf5") app = Flask(__name__) from tensorflow.keras.preprocessing.text import tokenizer_from_json import json with open("tokenizer.json", 'r') as f: tokenizer_data = f.read() tokenizer_config = json.loads(tokenizer_data) tokenizer = tokenizer_from_json(tokenizer_config) print(tokenizer) @app.route('/') def home(): return render_template('index.html') @app.route('/predict',methods=['POST']) def predict(): new_review = [str(x) for x in request.form.values()] print(new_review) # data = pd.DataFrame(new_review) # data.columns = ['new_review'] sequences = tokenizer.texts_to_sequences(new_review) print(sequences) padded_sequences = pad_sequences(sequences, maxlen=200,padding='post', value=0) predictions = model.predict(padded_sequences) print(predictions) if predictions<.5: return render_template('index.html', prediction_text='Negative') else: return render_template('index.html', prediction_text='Positive') if __name__ == "__main__": app.run(host='0.0.0.0',port=8080)