Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
from tensorflow.keras.datasets import imdb
|
4 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
word_index = imdb.get_word_index()
|
8 |
+
max_num_palabras = 2000
|
9 |
+
|
10 |
+
def reviewnueva(review, word_index, max_num_palabras):
|
11 |
+
sequence = []
|
12 |
+
for word in review.split():
|
13 |
+
index = word_index.get(word.lower(), 0)
|
14 |
+
if index < max_num_palabras:
|
15 |
+
sequence.append(index)
|
16 |
+
return sequence
|
17 |
+
|
18 |
+
model = tf.keras.models.load_model("opiniones.h5")
|
19 |
+
|
20 |
+
def predict_sentimiento(review):
|
21 |
+
sequence = reviewnueva(review, word_index)
|
22 |
+
prediccion = model.predict(sequence)
|
23 |
+
if prediccion[0][0]>=0.5:
|
24 |
+
sentimiento = "Positivo"
|
25 |
+
else:
|
26 |
+
sentimiento = "Negativo"
|
27 |
+
return sentimiento
|
28 |
+
|
29 |
+
st.title("Ingrese una review para poder calificar como positiva o negativa")
|
30 |
+
review = st.text_area("Ingrese reseña aquí", height = 200)
|
31 |
+
if st.button("Predecir sentimiento"):
|
32 |
+
if review:
|
33 |
+
sentimiento = predict_sentimiento(review)
|
34 |
+
st.write(f'El sentimiento es: {sentimiento}')
|
35 |
+
else:
|
36 |
+
st.write(f'Ingrese una review')
|