julio07cesar10 commited on
Commit
1492f1f
1 Parent(s): d9e0204

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
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.processing.secuence import pad_sequences
5
  import numpy as np
6
 
7
  word_index = imdb.get_word_index()
8
- maximo_num_palabras = 20000
9
 
10
- def reviewnueva(review, word_index, maximo_num_palabras):
11
- sequence = []
12
  for word in review.split():
13
  index = word_index.get(word.lower(), 0)
14
- if index < maximo_num_palabras:
15
- sequence.append(index)
16
- return sequence
17
 
18
  model = tf.keras.models.load_model("opiniones.h5")
19
- def predict_sentimiento(review)
20
- sequence = reviewnueva(review, word_index)
 
 
 
21
  if prediction [0] [0]>=0.5 :
22
  sentimiento = "Positivo"
23
  else:
24
  sentimiento = "Negativo"
25
- return predict_sentimiento
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
- sentiemiento = predict_sentimiento(review)
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')