Spaces:
Sleeping
Sleeping
julio07cesar10
commited on
Commit
•
1492f1f
1
Parent(s):
d9e0204
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,38 @@
|
|
1 |
import streamlit as st
|
2 |
import tensorflow as tf
|
3 |
from tensorflow.keras.datasets import imdb
|
4 |
-
from tensorflow.keras.
|
5 |
import numpy as np
|
6 |
|
7 |
word_index = imdb.get_word_index()
|
8 |
-
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
for word in review.split():
|
13 |
index = word_index.get(word.lower(), 0)
|
14 |
-
if index <
|
15 |
-
|
16 |
-
return
|
17 |
|
18 |
model = tf.keras.models.load_model("opiniones.h5")
|
19 |
-
def predict_sentimiento(review)
|
20 |
-
|
|
|
|
|
|
|
21 |
if prediction [0] [0]>=0.5 :
|
22 |
sentimiento = "Positivo"
|
23 |
else:
|
24 |
sentimiento = "Negativo"
|
25 |
-
return
|
26 |
|
27 |
st.title("Ingrese una review para poder calificarla como positiva o negativa")
|
28 |
review = st.text_area("Ingrese reseña aqui", height=200)
|
29 |
|
30 |
if st.button("Predicir sentimiento"):
|
31 |
if review:
|
32 |
-
|
33 |
st.write(f'El sentimiento es: {sentimiento}')
|
34 |
else:
|
35 |
st.write(f'Ingrese una review')
|
|
|
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_words = 20000
|
9 |
|
10 |
+
def review_to_sequences(review, word_index, max_words):
|
11 |
+
sequences = []
|
12 |
for word in review.split():
|
13 |
index = word_index.get(word.lower(), 0)
|
14 |
+
if index < max_words:
|
15 |
+
sequences.append(index)
|
16 |
+
return sequences
|
17 |
|
18 |
model = tf.keras.models.load_model("opiniones.h5")
|
19 |
+
def predict_sentimiento(review):
|
20 |
+
sequences = review_to_sequences(review, word_index, max_words)
|
21 |
+
sequences = np.array(sequences)
|
22 |
+
sequences = pad_sequences([sequences], maxlen=1000)
|
23 |
+
prediction = model.predict(sequences)
|
24 |
if prediction [0] [0]>=0.5 :
|
25 |
sentimiento = "Positivo"
|
26 |
else:
|
27 |
sentimiento = "Negativo"
|
28 |
+
return sentimiento
|
29 |
|
30 |
st.title("Ingrese una review para poder calificarla como positiva o negativa")
|
31 |
review = st.text_area("Ingrese reseña aqui", height=200)
|
32 |
|
33 |
if st.button("Predicir sentimiento"):
|
34 |
if review:
|
35 |
+
sentimiento = predict_sentimiento(review)
|
36 |
st.write(f'El sentimiento es: {sentimiento}')
|
37 |
else:
|
38 |
st.write(f'Ingrese una review')
|