Spaces:
Sleeping
Sleeping
File size: 1,215 Bytes
2170af7 1492f1f 2170af7 1492f1f 2170af7 1492f1f 2170af7 1492f1f 2170af7 1492f1f 2170af7 1492f1f 2170af7 abdaba4 2170af7 1492f1f 2170af7 d9e0204 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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()
max_words = 20000
def review_to_sequences(review, word_index, max_words):
sequences = []
for word in review.split():
index = word_index.get(word.lower(), 0)
if index < max_words:
sequences.append(index)
return sequences
model = tf.keras.models.load_model("opiniones.h5")
def predict_sentimiento(review):
sequences = review_to_sequences(review, word_index, max_words)
sequences = np.array(sequences)
sequences = pad_sequences([sequences], maxlen=1000)
prediction = model.predict(sequences)
if prediction [0] [0]>=0.5 :
sentimiento = "Positivo"
else:
sentimiento = "Negativo"
return sentimiento
st.title("Ingrese una review para poder calificarla como positiva o negativa")
review = st.text_area("Ingrese reseña aqui", height=200)
if st.button("Predicir sentimiento"):
if review:
sentimiento = predict_sentimiento(review)
st.write(f'El sentimiento es: {sentimiento}')
else:
st.write(f'Ingrese una review') |