davidlee1102
commited on
Commit
•
f0372d1
1
Parent(s):
2f8c020
Fixes bug
Browse files- app.py +1 -3
- emotion_model.py +3 -1
- pre_processing_data.py +4 -2
app.py
CHANGED
@@ -1,16 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
from emotion_model import emotion_predict
|
4 |
-
from pre_processing_data import user_capture
|
5 |
|
6 |
name = st.text_input("Enter your sentence here")
|
7 |
if (st.button('Submit')):
|
8 |
result = name.title()
|
9 |
try:
|
10 |
result_check = emotion_predict(result)
|
11 |
-
user_capture(result, result_check)
|
12 |
except Exception as E:
|
13 |
result_check = "Error"
|
14 |
print(E)
|
15 |
-
|
16 |
st.success(result_check)
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
from emotion_model import emotion_predict
|
|
|
4 |
|
5 |
name = st.text_input("Enter your sentence here")
|
6 |
if (st.button('Submit')):
|
7 |
result = name.title()
|
8 |
try:
|
9 |
result_check = emotion_predict(result)
|
|
|
10 |
except Exception as E:
|
11 |
result_check = "Error"
|
12 |
print(E)
|
|
|
13 |
st.success(result_check)
|
14 |
+
user_response = st.text_input("Please give your emotion that you are thinking is correct")
|
emotion_model.py
CHANGED
@@ -3,7 +3,7 @@ import tensorflow as tf
|
|
3 |
import tensorflow_addons as tfa
|
4 |
|
5 |
from constance_data import emotion_track_list, decode_cut_list
|
6 |
-
from pre_processing_data import preprocessing_data, pre_processing_data_2, text_transform
|
7 |
|
8 |
|
9 |
def emotion_predict(sentence: str):
|
@@ -12,6 +12,7 @@ def emotion_predict(sentence: str):
|
|
12 |
model = tf.keras.models.load_model("model/nlp_surrey_coursework_hunglenhat")
|
13 |
model.compile(loss='sparse_categorical_crossentropy',
|
14 |
optimizer=tfa.optimizers.AdamW(learning_rate=lr, weight_decay=wd), metrics=['accuracy'])
|
|
|
15 |
sentence = pre_processing_data_2(sentence)
|
16 |
if not sentence:
|
17 |
sentence = preprocessing_data(sentence)
|
@@ -23,4 +24,5 @@ def emotion_predict(sentence: str):
|
|
23 |
print(E)
|
24 |
index_max = np.argmax(sentence)
|
25 |
result = emotion_track_list[decode_cut_list[index_max]]
|
|
|
26 |
return result
|
|
|
3 |
import tensorflow_addons as tfa
|
4 |
|
5 |
from constance_data import emotion_track_list, decode_cut_list
|
6 |
+
from pre_processing_data import preprocessing_data, pre_processing_data_2, text_transform, user_capture
|
7 |
|
8 |
|
9 |
def emotion_predict(sentence: str):
|
|
|
12 |
model = tf.keras.models.load_model("model/nlp_surrey_coursework_hunglenhat")
|
13 |
model.compile(loss='sparse_categorical_crossentropy',
|
14 |
optimizer=tfa.optimizers.AdamW(learning_rate=lr, weight_decay=wd), metrics=['accuracy'])
|
15 |
+
sentence_temp = sentence
|
16 |
sentence = pre_processing_data_2(sentence)
|
17 |
if not sentence:
|
18 |
sentence = preprocessing_data(sentence)
|
|
|
24 |
print(E)
|
25 |
index_max = np.argmax(sentence)
|
26 |
result = emotion_track_list[decode_cut_list[index_max]]
|
27 |
+
user_capture(sentence_temp, result)
|
28 |
return result
|
pre_processing_data.py
CHANGED
@@ -86,13 +86,15 @@ def preprocessing_data(string_text):
|
|
86 |
return string_output
|
87 |
|
88 |
|
89 |
-
def user_capture(user_input,
|
90 |
dataframe_capture = pd.read_csv('user_logs.csv')
|
91 |
user_input_logs = pd.DataFrame({
|
92 |
"user_input": [user_input],
|
93 |
-
"emotion_predict": [
|
94 |
"time_logs": [datetime.now()],
|
95 |
})
|
96 |
|
97 |
dataframe_capture = pd.concat([dataframe_capture, user_input_logs], ignore_index=True)
|
98 |
dataframe_capture.to_csv("user_logs.csv", index=False)
|
|
|
|
|
|
86 |
return string_output
|
87 |
|
88 |
|
89 |
+
def user_capture(user_input, emotion_prd):
|
90 |
dataframe_capture = pd.read_csv('user_logs.csv')
|
91 |
user_input_logs = pd.DataFrame({
|
92 |
"user_input": [user_input],
|
93 |
+
"emotion_predict": [emotion_prd],
|
94 |
"time_logs": [datetime.now()],
|
95 |
})
|
96 |
|
97 |
dataframe_capture = pd.concat([dataframe_capture, user_input_logs], ignore_index=True)
|
98 |
dataframe_capture.to_csv("user_logs.csv", index=False)
|
99 |
+
print("Done Recorded")
|
100 |
+
return None
|