Sambhavnoobcoder commited on
Commit
72cc2a3
·
1 Parent(s): 078e4df

(old code) X (new code)

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -4,6 +4,21 @@ import tensorflow as tf
4
  # Load the saved model
5
  model = tf.keras.models.load_model("sentimentality.h5")
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def predict_sentiment(text):
8
  # preprocess input text
9
  processed_text = preprocess(text)
 
4
  # Load the saved model
5
  model = tf.keras.models.load_model("sentimentality.h5")
6
 
7
+ def preprocess(text):
8
+ # Tokenize the text into a list of words
9
+ words = text.strip().lower().split()
10
+ # Load the vocabulary
11
+ with open('vocabulary.txt', 'r') as f:
12
+ vocab = f.read().splitlines()
13
+ # Convert the words to indices in the vocabulary
14
+ word_indices = [vocab.index(word) if word in vocab else 0 for word in words]
15
+ # Pad the sequence with zeros to a fixed length of 500
16
+ padded_indices = np.zeros(500, dtype=np.int32)
17
+ padded_indices[:len(word_indices)] = word_indices
18
+ # Convert the sequence to a tensor
19
+ tensor = np.expand_dims(padded_indices, axis=0)
20
+ return tensor
21
+
22
  def predict_sentiment(text):
23
  # preprocess input text
24
  processed_text = preprocess(text)