Sentic commited on
Commit
98049e3
ยท
1 Parent(s): 936f769

Upload 6 files

Browse files
Files changed (6) hide show
  1. Emotion_Detection.ipynb +0 -0
  2. data.db +0 -0
  3. model.pkl +3 -0
  4. requirements.txt +12 -0
  5. streamlit_app.py +105 -0
  6. track_utils.py +32 -0
Emotion_Detection.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
data.db ADDED
Binary file (12.3 kB). View file
 
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:069a4e3f9f53e5be5fe8576c3aae27d6f32bdf753328dc42019c59ab2ae82b8e
3
+ size 2015656
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ eli5
2
+ lime
3
+ neattext
4
+ pandas
5
+ spacy
6
+ numpy
7
+ seaborn
8
+ altair
9
+ streamlit
10
+ plotly
11
+ joblib
12
+ streamlit
streamlit_app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Core Packages !!
2
+ import streamlit as st
3
+ from datetime import datetime
4
+ import joblib
5
+ import pandas as pd
6
+ import numpy as np
7
+ import altair as alt
8
+ import plotly.express as px
9
+ #Utils
10
+ import joblib
11
+ from track_utils import create_page_visited_table,add_page_visited_details,view_all_page_visited_details,add_prediction_details,view_all_prediction_details,create_emotionclf_table
12
+ pipe_lr = joblib.load('model.pkl')
13
+ # Fxn
14
+ def predict_emotions(docx):
15
+ results = pipe_lr.predict([docx])
16
+ return results[0]
17
+
18
+ def get_prediction_proba(docx):
19
+ results = pipe_lr.predict_proba([docx])
20
+ return results
21
+
22
+ emotions_emoji_dict = {"anger":"๐Ÿ˜ ","disgust":"๐Ÿคฎ", "fear":"๐Ÿ˜จ๐Ÿ˜ฑ", "happy":"๐Ÿค—", "joy":"๐Ÿ˜‚", "neutral":"๐Ÿ˜", "sad":"๐Ÿ˜”", "sadness":"๐Ÿ˜”", "shame":"๐Ÿ˜ณ", "surprise":"๐Ÿ˜ฎ"}
23
+
24
+
25
+ # Main Application
26
+ def main():
27
+ st.title("Emotion Classifier App")
28
+ menu = ["Home","Monitor","About"]
29
+ choice = st.sidebar.selectbox("Menu",menu)
30
+ create_page_visited_table()
31
+ create_emotionclf_table()
32
+ if choice == "Home":
33
+ add_page_visited_details("Home",datetime.now())
34
+ st.subheader("Home-Emotion In Text")
35
+
36
+ with st.form(key='emotion_clf_form'):
37
+ raw_text = st.text_area("Type Here")
38
+ submit_text = st.form_submit_button(label='Submit')
39
+
40
+ if submit_text:
41
+ col1, col2 = st.columns(2)
42
+
43
+ # Apply Fxn Here
44
+ prediction = predict_emotions(raw_text)
45
+ probability = get_prediction_proba(raw_text)
46
+
47
+ add_prediction_details(raw_text,prediction,np.max(probability),datetime.now())
48
+
49
+ with col1:
50
+ st.success("Original Text")
51
+ st.write(raw_text)
52
+
53
+ st.success("Prediction")
54
+ emoji_icon = emotions_emoji_dict[prediction]
55
+ st.write("{}:{}".format(prediction,emoji_icon))
56
+ st.write("Confidence:{}".format(np.max(probability)))
57
+
58
+
59
+
60
+ with col2:
61
+ st.success("Prediction Probability")
62
+ # st.write(probability)
63
+ proba_df = pd.DataFrame(probability,columns=pipe_lr.classes_)
64
+ # st.write(proba_df.T)
65
+ proba_df_clean = proba_df.T.reset_index()
66
+ proba_df_clean.columns = ["emotions","probability"]
67
+
68
+ fig = alt.Chart(proba_df_clean).mark_bar().encode(x='emotions',y='probability',color='emotions')
69
+ st.altair_chart(fig,use_container_width=True)
70
+
71
+
72
+
73
+ elif choice == "Monitor":
74
+ add_page_visited_details("Monitor",datetime.now())
75
+ st.subheader("Monitor App")
76
+
77
+ with st.expander("Page Metrics"):
78
+ page_visited_details = pd.DataFrame(view_all_page_visited_details(),columns=['Pagename','Time_of_Visit'])
79
+ st.dataframe(page_visited_details)
80
+
81
+ pg_count = page_visited_details['Pagename'].value_counts().rename_axis('Pagename').reset_index(name='Counts')
82
+ c = alt.Chart(pg_count).mark_bar().encode(x='Pagename',y='Counts',color='Pagename')
83
+ st.altair_chart(c,use_container_width=True)
84
+
85
+ p = px.pie(pg_count,values='Counts',names='Pagename')
86
+ st.plotly_chart(p,use_container_width=True)
87
+
88
+ with st.expander('Emotion Classifier Metrics'):
89
+ df_emotions = pd.DataFrame(view_all_prediction_details(),columns=['Rawtext','Prediction','Probability','Time_of_Visit'])
90
+ st.dataframe(df_emotions)
91
+
92
+ prediction_count = df_emotions['Prediction'].value_counts().rename_axis('Prediction').reset_index(name='Counts')
93
+ pc = alt.Chart(prediction_count).mark_bar().encode(x='Prediction',y='Counts',color='Prediction')
94
+ st.altair_chart(pc,use_container_width=True)
95
+
96
+
97
+
98
+ else:
99
+ st.subheader("About")
100
+ add_page_visited_details("About",datetime.now())
101
+
102
+
103
+
104
+ if __name__ == '__main__':
105
+ main()
track_utils.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Load Database Pkg
2
+ import sqlite3
3
+ conn = sqlite3.connect('data.db')
4
+ c = conn.cursor()
5
+
6
+
7
+ # Fxn
8
+ def create_page_visited_table():
9
+ c.execute('CREATE TABLE IF NOT EXISTS pageTrackTable(pagename TEXT,timeOfvisit TIMESTAMP)')
10
+
11
+ def add_page_visited_details(pagename,timeOfvisit):
12
+ c.execute('INSERT INTO pageTrackTable(pagename,timeOfvisit) VALUES(?,?)',(pagename,timeOfvisit))
13
+ conn.commit()
14
+
15
+ def view_all_page_visited_details():
16
+ c.execute('SELECT * FROM pageTrackTable')
17
+ data = c.fetchall()
18
+ return data
19
+
20
+
21
+ # Fxn To Track Input & Prediction
22
+ def create_emotionclf_table():
23
+ c.execute('CREATE TABLE IF NOT EXISTS emotionclfTable(rawtext TEXT,prediction TEXT,probability NUMBER,timeOfvisit TIMESTAMP)')
24
+
25
+ def add_prediction_details(rawtext,prediction,probability,timeOfvisit):
26
+ c.execute('INSERT INTO emotionclfTable(rawtext,prediction,probability,timeOfvisit) VALUES(?,?,?,?)',(rawtext,prediction,probability,timeOfvisit))
27
+ conn.commit()
28
+
29
+ def view_all_prediction_details():
30
+ c.execute('SELECT * FROM emotionclfTable')
31
+ data = c.fetchall()
32
+ return data