|
|
|
import streamlit as st |
|
import tensorflow as tf |
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
@st.cache_data |
|
def load_sentiment_model(): |
|
model = load_model('model.keras') |
|
return model |
|
|
|
|
|
def predict_sentiment(review_text, model): |
|
|
|
pred = model.predict([review_text]) |
|
prediction = tf.where(pred >= 0.5, 1, 0) |
|
|
|
|
|
predictions_list = prediction.numpy().flatten().tolist() |
|
|
|
|
|
predictions_recommended = ['The author recommending this product' if x == 1 else 'The author not recommending this product' for x in predictions_list] |
|
|
|
return predictions_recommended |
|
|
|
|
|
def app(): |
|
st.title('Make Predictions') |
|
|
|
|
|
model = load_sentiment_model() |
|
|
|
|
|
user_input = st.text_area("Enter your review:", "") |
|
|
|
if st.button("Predict"): |
|
if user_input: |
|
|
|
with st.spinner('Predicting...'): |
|
|
|
predictions = predict_sentiment(user_input, model) |
|
|
|
|
|
st.success(f'Prediction: {predictions[0]}') |
|
else: |
|
st.warning("Please enter a review.") |
|
|
|
if __name__ == '__main__': |
|
app() |
|
|