-
Notifications
You must be signed in to change notification settings - Fork 0
/
onlineSentiment.py
31 lines (22 loc) · 1.13 KB
/
onlineSentiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#note to self, for running on my Desktop I have to use pyenv to install python 3.7.0 and then install strealit v 0.62.0
#otherwise I get some junk about "illegal hardware instruction"
import streamlit as st
import pickle
from science import classify
import sys
#idk what it is about the import system, but it never seems to just work
sys.path.append("./science")
from helpers import token_lemma
loaded_model = pickle.load(open("./science/model.pkl", 'rb'))
loaded_vectorizer = pickle.load(open("./science/vectorizer.pkl", 'rb'))
model = classify.sentimenter(loaded_model, loaded_vectorizer)
st.title('An online sentiment classifier')
st.write("Enter text, up to 140 characters, that you'd like to know the sentiment of.")
st.write("Sorry, emojis will be ignored 😭")
sentence = st.text_area('Input your text here:', "Data science is great!")
maxlen = 140
if len(sentence) > maxlen:
st.error(f"Input too long by {len(sentence) - maxlen} characters, please try again.")
else:
result = model.get_probs(sentence)
st.success(f"There's a {result[0]*100:.2f}% chance this is negative and a {result[1]*100:.2f}% chance it's positive.")