Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ st.title("Movie Reviews: An NLP Sentiment analysis")
|
|
16 |
|
17 |
#################################################################### Cache the model loading
|
18 |
|
19 |
-
@st.
|
20 |
def load_model():
|
21 |
model_pkl_file = "sentiment_model.pkl"
|
22 |
with open(model_pkl_file, 'rb') as file:
|
@@ -24,12 +24,12 @@ def load_model():
|
|
24 |
return model
|
25 |
|
26 |
def load_cnn():
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
|
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)
|
|
|
16 |
|
17 |
#################################################################### Cache the model loading
|
18 |
|
19 |
+
@st.cache(allow_output_mutation=True)
|
20 |
def load_model():
|
21 |
model_pkl_file = "sentiment_model.pkl"
|
22 |
with open(model_pkl_file, 'rb') as file:
|
|
|
24 |
return model
|
25 |
|
26 |
def load_cnn():
|
27 |
+
model = CNN(16236, 300, 128, [3, 8], 0.5, 2)
|
28 |
+
model.load_state_dict(torch.load('model_cnn.pkl', map_location=torch.device('cpu')))
|
29 |
+
model.eval()
|
30 |
+
return model
|
31 |
|
32 |
+
def predict_sentiment(text, model, vocab=16236, torch_text = False):
|
|
|
33 |
tokenizer = get_tokenizer("basic_english")
|
34 |
if torch_text == True:
|
35 |
processor.transform(text)
|