Update app.py
Browse files
app.py
CHANGED
@@ -49,9 +49,17 @@ def predict_emotions(sentence):
|
|
49 |
result = le_departure.inverse_transform(
|
50 |
np.argmax(model.predict(sentence), axis=-1))[0]
|
51 |
proba = np.max(model.predict(sentence))
|
52 |
-
print(
|
53 |
-
|
54 |
-
return result, proba
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
def sentence_cleaning(sentence):
|
@@ -70,18 +78,7 @@ def sentence_cleaning(sentence):
|
|
70 |
|
71 |
|
72 |
def main():
|
73 |
-
|
74 |
-
"disgust":"🤮",
|
75 |
-
"fear":"😨😱",
|
76 |
-
"happy":"🤗",
|
77 |
-
"joy":"😂",
|
78 |
-
"neutral":"😐",
|
79 |
-
"sad":"😔",
|
80 |
-
"sadness":"😔",
|
81 |
-
"shame":"😳",
|
82 |
-
"surprise":"😮"
|
83 |
-
}
|
84 |
-
st.title("🤮😨Emotion Classifier😱😂")
|
85 |
menu = ["Home", "Monitor"]
|
86 |
choice = st.sidebar.selectbox("Menu", menu)
|
87 |
if choice == "Home":
|
@@ -92,20 +89,26 @@ def main():
|
|
92 |
submit_text = st.form_submit_button(label='Submit')
|
93 |
|
94 |
if submit_text:
|
95 |
-
col1, col2 = st.
|
96 |
|
97 |
# Apply Fxn Here
|
98 |
-
res, proba = predict_emotions(raw_text)
|
99 |
|
100 |
with col1:
|
101 |
st.success("Original Text")
|
102 |
st.write(raw_text)
|
103 |
|
104 |
st.success("Prediction")
|
105 |
-
st.write("{}:{}".format(res,
|
106 |
st.write("Confidence:{}".format(proba))
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
else:
|
111 |
st.subheader("About")
|
|
|
49 |
result = le_departure.inverse_transform(
|
50 |
np.argmax(model.predict(sentence), axis=-1))[0]
|
51 |
proba = np.max(model.predict(sentence))
|
52 |
+
print()
|
53 |
+
|
54 |
+
return result, proba, get_all_result(model.predict(sentence))
|
55 |
+
|
56 |
+
|
57 |
+
def get_all_result(prediction):
|
58 |
+
dict = {}
|
59 |
+
for element in prediction:
|
60 |
+
for i in range(0, len(element)):
|
61 |
+
dict[element[i]] = le_departure.inverse_transform([i])
|
62 |
+
return dict
|
63 |
|
64 |
|
65 |
def sentence_cleaning(sentence):
|
|
|
78 |
|
79 |
|
80 |
def main():
|
81 |
+
st.title("Emotion Classifier")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
menu = ["Home", "Monitor"]
|
83 |
choice = st.sidebar.selectbox("Menu", menu)
|
84 |
if choice == "Home":
|
|
|
89 |
submit_text = st.form_submit_button(label='Submit')
|
90 |
|
91 |
if submit_text:
|
92 |
+
col1, col2 = st.beta_columns(2)
|
93 |
|
94 |
# Apply Fxn Here
|
95 |
+
res, proba, total_result = predict_emotions(raw_text)
|
96 |
|
97 |
with col1:
|
98 |
st.success("Original Text")
|
99 |
st.write(raw_text)
|
100 |
|
101 |
st.success("Prediction")
|
102 |
+
st.write("{}:{}".format(res, proba))
|
103 |
st.write("Confidence:{}".format(proba))
|
104 |
+
print(total_result.keys())
|
105 |
+
print(total_result.values())
|
106 |
+
|
107 |
+
source = pd.DataFrame({'Proba': list(total_result.keys()), 'Emotion': list(total_result.values())})
|
108 |
+
|
109 |
+
fig = alt.Chart(source).mark_bar().encode(x='Emotion',y='Proba',color='Emotion')
|
110 |
+
st.altair_chart(fig,use_container_width=True)
|
111 |
+
|
112 |
|
113 |
else:
|
114 |
st.subheader("About")
|