|
import streamlit as st |
|
import numpy as np |
|
from keras.models import load_model |
|
from PIL import Image |
|
from tensorflow.keras.preprocessing.sequence import pad_sequences |
|
|
|
|
|
model = load_model('model_gru_2') |
|
|
|
def run(): |
|
|
|
image = Image.open('twittersentiment.jpg') |
|
st.image(image, caption = 'Twitter Sentiment') |
|
|
|
with st.form('sentiment_prediction'): |
|
|
|
input_text = st.text_area('Input Text', '', help='Enter the text for sentiment prediction') |
|
|
|
|
|
submitted = st.form_submit_button('Predict') |
|
|
|
|
|
if submitted: |
|
|
|
|
|
input_text = input_text.lower() |
|
|
|
|
|
predictions = model.predict(np.array([input_text])) |
|
|
|
|
|
predicted_class = np.argmax(predictions[0]) |
|
class_labels = {0: 'Negative', 1: 'Positive', 2: 'Neutral'} |
|
predicted_label = class_labels[predicted_class] |
|
|
|
|
|
st.write('## Sentiment Prediction:') |
|
st.write('Input Text:', input_text) |
|
st.write('Predicted Class:', predicted_class) |
|
st.write('Predicted Label:', predicted_label) |
|
st.write('Prediction Probabilities:', predictions[0]) |
|
|
|
if __name__ == '__main__': |
|
run() |
|
|