Spaces:
Sleeping
Sleeping
import streamlit as st | |
import tensorflow as tf | |
from tensorflow.keras.datasets import imdb | |
from tensorflow.keras.preprocessing.sequence import pad_sequences | |
import numpy as np | |
word_index = imdb.get_word_index() | |
maximo_num_palabras = 20000 | |
def reviwnueva(review, word_index, maximo_num_palabras): | |
sequence = [] | |
for word in review.split(): | |
index = word_index.get(word.lower(), 0) | |
if index < maximo_num_palabras: | |
squence.append(index) | |
return sequence | |
model = tf.keras.models.load_model("opiniones.h5") | |
def predict_sentimiento(review): | |
sequence = reviwnueva(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 calificarla com positiva o negativa") | |
review = st.text_area("Ingrese reseña aqui", height=200) | |
if st.button("Predecir sentimiento"): | |
if review: | |
sentimineto = predict_sentimiento(review) | |
st.write(f"El sentimiento es: {sentimineto}") | |
else: | |
st.write(f'Ingrese una review') |