efeperro commited on
Commit
6c66e90
β€’
1 Parent(s): 2453d6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -8,6 +8,7 @@ nltk.download('punkt')
8
  download_if_non_existent('corpora/stopwords', 'stopwords')
9
  download_if_non_existent('taggers/averaged_perceptron_tagger', 'averaged_perceptron_tagger')
10
  download_if_non_existent('corpora/wordnet', 'wordnet')
 
11
 
12
 
13
  #################################################################### Streamlit interface
@@ -28,7 +29,8 @@ def load_cnn():
28
  model.eval()
29
 
30
  return model
31
- def predict_sentiment(text, model, vocab, tokenizer, torch_text = False):
 
32
  if torch_text == True:
33
  processor.transform(text)
34
  tokens = tokenizer(text)
@@ -75,7 +77,7 @@ with st.expander("Model 2: CNN Sentiment analysis"):
75
  user_input = st.text_area("Enter text here...", key='model2_input')
76
  if st.button('Analyze', key='model2_button'):
77
  # Displaying output
78
- result = predict_sentiment(user_input, model_2, torch_text=True)
79
  if result >= 0.5:
80
  st.write('The sentiment is: Positive πŸ˜€', key='model2_poswrite')
81
  else:
 
8
  download_if_non_existent('corpora/stopwords', 'stopwords')
9
  download_if_non_existent('taggers/averaged_perceptron_tagger', 'averaged_perceptron_tagger')
10
  download_if_non_existent('corpora/wordnet', 'wordnet')
11
+ from torchtext.data.utils import get_tokenizer
12
 
13
 
14
  #################################################################### Streamlit interface
 
29
  model.eval()
30
 
31
  return model
32
+ def predict_sentiment(text, model, vocab, torch_text = False):
33
+ tokenizer = get_tokenizer("basic_english")
34
  if torch_text == True:
35
  processor.transform(text)
36
  tokens = tokenizer(text)
 
77
  user_input = st.text_area("Enter text here...", key='model2_input')
78
  if st.button('Analyze', key='model2_button'):
79
  # Displaying output
80
+ result = predict_sentiment(user_input, model_2, 16236, torch_text=True)
81
  if result >= 0.5:
82
  st.write('The sentiment is: Positive πŸ˜€', key='model2_poswrite')
83
  else: