Dwight18's picture
Update app.py
03e1267 verified
import streamlit as st
import tensorflow as tf
from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing import sequence
from tensorflow.keras.preprocessing.sequence import pad_sequences
import numpy as np
word_index = imdb.get_word_index()
max_num_palabras = 2000
def reviewnueva(review, word_index, max_num_palabras):
sequence = []
for word in review.split():
index = word_index.get(word.lower(), 0)
if index < max_num_palabras:
sequence.append(index)
return sequence
model = tf.keras.models.load_model("opiniones.h5")
def predict_sentimiento(review):
sequence = reviewnueva(review, word_index)
prediccion = model.predict(sequence)
if prediccion[0][0]>=0.5:
sentimiento = "Positivo"
else:
sentimiento = "Negativo"
return sentimiento
st.title("Ingrese una review para poder calificar como positiva o negativa")
review = st.text_area("Ingrese reseña aquí", height = 200)
if st.button("Predecir sentimiento"):
if review:
sentimiento = predict_sentimiento(review)
st.write(f'El sentimiento es: {sentimiento}')
else:
st.write(f'Ingrese una review')