srijan2024's picture
app
a1b6358
import numpy as np
import string
import streamlit as st
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
import nltk
import json
from tensorflow.keras.models import load_model
import tensorflow as tf
model = load_model("E:\CODES\pythonProject7\_best_model_LSTM.hdf5")
from tensorflow.keras.preprocessing.text import tokenizer_from_json
with open("D:/Analysis_sentiment/tokenizer.json", 'r') as f:
tokenizer_data = f.read()
tokenizer_config = json.loads(tokenizer_data)
tokenizer = tokenizer_from_json(tokenizer_config)
def predict_sentiment(review):
sequences = tokenizer.texts_to_sequences([review])
padded_sequences = pad_sequences(sequences, maxlen=200, padding='post', value=0)
prediction = model.predict(padded_sequences)[0][0]
return prediction
st.title('Sentiment Analysis')
review = st.text_input('Enter your review')
if review:
prediction = predict_sentiment(review)
if prediction < 0.5:
st.write('Negative')
else:
st.write('Positive')
if __name__ == '__main__':
app.run()