|
|
""" |
|
|
Graded Challenge 7 |
|
|
Nama: Devin Yaung Lee |
|
|
Batch: HCK-009 |
|
|
// eda.py // |
|
|
program ini menjadi base model EDA interface. |
|
|
""" |
|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import numpy as np |
|
|
from tensorflow import keras |
|
|
from keras.models import load_model |
|
|
import os |
|
|
|
|
|
import nltk |
|
|
|
|
|
nltk.download('punkt') |
|
|
|
|
|
|
|
|
from file import text_preprocessing |
|
|
|
|
|
|
|
|
def make_prediction(model, texts, text_preprocessing): |
|
|
|
|
|
preprocessed_texts = [text_preprocessing(text) for text in texts] |
|
|
|
|
|
|
|
|
predictions = model.predict(preprocessed_texts) |
|
|
return predictions |
|
|
|
|
|
def run(): |
|
|
st.title("Predict the User Sentiment") |
|
|
|
|
|
|
|
|
|
|
|
model = load_model('model_lstm') |
|
|
|
|
|
|
|
|
user_input = st.text_area("Enter your review:") |
|
|
|
|
|
if st.button('Predict'): |
|
|
|
|
|
preprocessed_text = text_preprocessing(user_input) |
|
|
|
|
|
|
|
|
predictions = make_prediction(model, [preprocessed_text], text_preprocessing) |
|
|
|
|
|
|
|
|
predicted_class = np.argmax(predictions, axis=1)[0] |
|
|
|
|
|
|
|
|
class_labels = {0: 'bad', 1: 'neutral', 2: 'good'} |
|
|
predicted_label = class_labels[predicted_class] |
|
|
|
|
|
|
|
|
if predicted_label == 'bad': |
|
|
st.error("The model predicts the sentiment as bad.") |
|
|
elif predicted_label == 'neutral': |
|
|
st.warning("The model predicts the sentiment as neutral.") |
|
|
else: |
|
|
st.success("The model predicts the sentiment as good.") |