Spaces:
Runtime error
Runtime error
refactor: diabled 'ONLY' Utterance/Debate Judgement Anlaysis function
Browse files
app.py
CHANGED
@@ -124,11 +124,8 @@ def page_4_5_controller():
|
|
124 |
def page_5_6_controller():
|
125 |
st.session_state.page = "Page 6"
|
126 |
|
127 |
-
def
|
128 |
-
|
129 |
-
|
130 |
-
def page_2_7_controller():
|
131 |
-
st.session_state.page = "Page 7"
|
132 |
|
133 |
def page_n_1_controller():
|
134 |
st.session_state.page = "Page 1"
|
@@ -172,14 +169,15 @@ def page1():
|
|
172 |
max_chars=100,
|
173 |
placeholder="Enter user ID",
|
174 |
)
|
175 |
-
|
176 |
|
177 |
if user_input:
|
178 |
if validate_user_id(user_input):
|
179 |
save_info(user_input)
|
|
|
180 |
st.session_state.disabled = False
|
181 |
else:
|
182 |
-
|
183 |
st.session_state.disabled = True
|
184 |
else:
|
185 |
st.session_state.disabled = True
|
@@ -206,13 +204,17 @@ def page2():
|
|
206 |
# add controller
|
207 |
if option_result == "Total Debate":
|
208 |
page_control_func = page_2_3_controller
|
|
|
209 |
elif option_result == "Evaluation Only & Analyzing Utterances":
|
210 |
-
|
|
|
|
|
211 |
|
212 |
st.button(
|
213 |
label='Next',
|
214 |
type='primary',
|
215 |
-
|
|
|
216 |
)
|
217 |
|
218 |
|
@@ -231,6 +233,7 @@ def page3():
|
|
231 |
if not debate_history:
|
232 |
st.info('There is no previous debate history', icon="โน๏ธ")
|
233 |
|
|
|
234 |
print(debate_history)
|
235 |
|
236 |
_, _, pre, home = st.columns([5, 5, 1, 1])
|
@@ -638,6 +641,7 @@ def page5():
|
|
638 |
|
639 |
try :
|
640 |
response = generate_response(user_input)
|
|
|
641 |
print("response", response)
|
642 |
except:
|
643 |
openai_error_bottom.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="โ ๏ธ")
|
@@ -654,7 +658,7 @@ def page5():
|
|
654 |
value_of_partition_key=st.session_state.user_id,
|
655 |
limit_num=1
|
656 |
)
|
657 |
-
|
658 |
print(f'debate_main_latest_data : {debate_main_latest_data}')
|
659 |
if not debate_main_latest_data:
|
660 |
turn_num = 0
|
@@ -711,6 +715,7 @@ def page5():
|
|
711 |
on_click=page_5_6_controller
|
712 |
)
|
713 |
|
|
|
714 |
print("#"*80)
|
715 |
pprint.pprint(st.session_state.to_dict())
|
716 |
print("#"*80)
|
@@ -847,118 +852,126 @@ def page6():
|
|
847 |
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
848 |
# st.session_state.debate_history
|
849 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
850 |
|
851 |
#########################################################
|
852 |
# Page7
|
853 |
#########################################################
|
854 |
|
855 |
-
def page7():
|
856 |
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
|
867 |
-
|
868 |
|
869 |
-
|
870 |
|
871 |
-
|
872 |
-
|
873 |
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
|
896 |
-
|
897 |
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
|
|
962 |
|
963 |
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
964 |
# st.session_state.debate_history
|
@@ -981,14 +994,13 @@ pages = {
|
|
981 |
"Page 4": page4, # ํ ๋ก ์ธ๋ถ์ฌํญ ์ค์
|
982 |
"Page 5": page5, # Total Debate
|
983 |
"Page 6": page6, # Evaluation Only
|
984 |
-
"Page 7": page7, # Analyzing Utterances
|
985 |
}
|
986 |
|
987 |
selection = st.session_state.page
|
|
|
988 |
print("selection:", selection)
|
989 |
|
990 |
page = pages[selection]
|
991 |
# Execute selected page function
|
992 |
page()
|
993 |
-
|
994 |
-
|
|
|
124 |
def page_5_6_controller():
|
125 |
st.session_state.page = "Page 6"
|
126 |
|
127 |
+
# def page_2_7_controller():
|
128 |
+
# st.session_state.page = "Page 7"
|
|
|
|
|
|
|
129 |
|
130 |
def page_n_1_controller():
|
131 |
st.session_state.page = "Page 1"
|
|
|
169 |
max_chars=100,
|
170 |
placeholder="Enter user ID",
|
171 |
)
|
172 |
+
message = st.empty()
|
173 |
|
174 |
if user_input:
|
175 |
if validate_user_id(user_input):
|
176 |
save_info(user_input)
|
177 |
+
message.success('User ID successfully verified!', icon="โ
")
|
178 |
st.session_state.disabled = False
|
179 |
else:
|
180 |
+
message.error('Please fill in correct User ID', icon="๐จ")
|
181 |
st.session_state.disabled = True
|
182 |
else:
|
183 |
st.session_state.disabled = True
|
|
|
204 |
# add controller
|
205 |
if option_result == "Total Debate":
|
206 |
page_control_func = page_2_3_controller
|
207 |
+
st.session_state.disabled = False
|
208 |
elif option_result == "Evaluation Only & Analyzing Utterances":
|
209 |
+
st.info('Sorry:( This function will be developed soon.', icon="โน๏ธ")
|
210 |
+
page_control_func = page_1_2_controller
|
211 |
+
st.session_state.disabled = True
|
212 |
|
213 |
st.button(
|
214 |
label='Next',
|
215 |
type='primary',
|
216 |
+
disabled=st.session_state.disabled,
|
217 |
+
on_click=page_control_func,
|
218 |
)
|
219 |
|
220 |
|
|
|
233 |
if not debate_history:
|
234 |
st.info('There is no previous debate history', icon="โน๏ธ")
|
235 |
|
236 |
+
#TODO delete!
|
237 |
print(debate_history)
|
238 |
|
239 |
_, _, pre, home = st.columns([5, 5, 1, 1])
|
|
|
641 |
|
642 |
try :
|
643 |
response = generate_response(user_input)
|
644 |
+
#TODO delete
|
645 |
print("response", response)
|
646 |
except:
|
647 |
openai_error_bottom.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="โ ๏ธ")
|
|
|
658 |
value_of_partition_key=st.session_state.user_id,
|
659 |
limit_num=1
|
660 |
)
|
661 |
+
#TODO delete
|
662 |
print(f'debate_main_latest_data : {debate_main_latest_data}')
|
663 |
if not debate_main_latest_data:
|
664 |
turn_num = 0
|
|
|
715 |
on_click=page_5_6_controller
|
716 |
)
|
717 |
|
718 |
+
#TODO must have to delete!!!!
|
719 |
print("#"*80)
|
720 |
pprint.pprint(st.session_state.to_dict())
|
721 |
print("#"*80)
|
|
|
852 |
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
853 |
# st.session_state.debate_history
|
854 |
|
855 |
+
############################################
|
856 |
+
# Visualization
|
857 |
+
############################################
|
858 |
+
|
859 |
+
# ์ด์ ์ ๊ธฐ๋ก๋ ๊ฐ์ด ์๋ค๋ฉด, ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฝ๋๋ค.
|
860 |
+
# ์ด์ ์ ๊ธฐ๋ก๋ ๊ฐ์ด ์๋ค๋ฉด, ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ์ง ์์ต๋๋ค.
|
861 |
+
|
862 |
|
863 |
#########################################################
|
864 |
# Page7
|
865 |
#########################################################
|
866 |
|
867 |
+
# def page7():
|
868 |
|
869 |
+
# # end time
|
870 |
+
# st.session_state.end_time = time.time()
|
871 |
+
# st.session_state.debate_time = st.session_state.end_time - st.session_state.start_time
|
872 |
|
873 |
+
# _, _, pre, home = st.columns([5, 5, 1, 1])
|
874 |
+
# with pre:
|
875 |
+
# st.button("๐", on_click=page_1_2_controller, use_container_width=True)
|
876 |
+
# with home:
|
877 |
+
# st.button("๐", on_click=page_n_1_controller, use_container_width=True)
|
878 |
|
879 |
+
# st.header('Total Debate Evaluation')
|
880 |
|
881 |
+
# tab1, tab2 = st.tabs(['Debate Judgement', 'Debate Analysis'])
|
882 |
|
883 |
+
# with tab1:
|
884 |
+
# st.header("Debate Evaluation")
|
885 |
|
886 |
+
# debate_themes = ['User-Bot', "User", "Bot"]
|
887 |
+
|
888 |
+
# # ์ ์ฒด, ์ ์ , ๋ด ์ธ ๊ฐ์ง ์ต์
์ค์ ์ ํ
|
889 |
+
# judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
890 |
+
|
891 |
+
# if st.session_state.judgement_result == "":
|
892 |
+
# with st.spinner('Wait for judgement result...'):
|
893 |
+
# judgement_result = ""
|
894 |
+
|
895 |
+
# user_debate_history = "".join(
|
896 |
+
# st.session_state.user_debate_history
|
897 |
+
# )
|
898 |
+
# bot_debate_history = "".join(
|
899 |
+
# st.session_state.bot_debate_history
|
900 |
+
# )
|
901 |
+
|
902 |
+
# judgement_result = debate_judgement(
|
903 |
+
# judgement_who,
|
904 |
+
# user_debate_history,
|
905 |
+
# bot_debate_history
|
906 |
+
# )
|
907 |
|
908 |
+
# st.session_state.judgement_result = judgement_result
|
909 |
|
910 |
+
# st.write("Debate Judgement Result")
|
911 |
+
# st.write(judgement_result)
|
912 |
+
|
913 |
+
# if judgement_result:
|
914 |
+
# put_item(
|
915 |
+
# table=dynamodb.Table('DEBO_evaluation'),
|
916 |
+
# item={
|
917 |
+
# 'user_id': st.session_state.user_id,
|
918 |
+
# 'time_stamp': time_stamp,
|
919 |
+
# 'judgement_text': judgement_result,
|
920 |
+
# 'session_num': int(st.session_state.session_num),
|
921 |
+
# }
|
922 |
+
# )
|
923 |
+
# st.success('Done!')
|
924 |
+
# else:
|
925 |
+
# st.write(st.session_state.judgement_result)
|
926 |
+
|
927 |
+
# with tab2:
|
928 |
+
# st.header('Debate Analysis')
|
929 |
+
|
930 |
+
# # ์ ์ ์ history๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ฐํ๋, ๋น์ถ ๋จ์ด, ๋ฐํ ์ต๊ด ์ธ ๊ฐ์ง๋ฅผ ๋ถ์
|
931 |
+
# user_history = st.session_state.user_debate_history
|
932 |
+
|
933 |
+
# # 1. ๋ฐํ๋: ์ด ๋จ์ด, ํ๊ท ์๋(๋จ์ด/์๊ฐ)๋ฅผ ํ๊ท ๋ฐํ๋ ํน์ ์ฐธ๊ณ ์งํ์ ๋น๊ตํด ์ ์
|
934 |
+
|
935 |
+
# # ์ด ๋จ์ด
|
936 |
+
# # ํ
์คํธ๋ฅผ ๋จ์ด๋ก ๋ถํ ํฉ๋๋ค.
|
937 |
+
# # ๊ฐ ๋จ์ด์ ๋น๋๋ฅผ ๊ณ์ฐํฉ๋๋ค.
|
938 |
+
# total_word_count = len(user_history)
|
939 |
+
# #total_word_count = len(user_history.split())
|
940 |
+
# st.write("Total Word Count: ", total_word_count)
|
941 |
+
|
942 |
+
# # ํ๊ท ์๋(๋จ์ด/์๊ฐ)
|
943 |
+
# #user_debate_time = st.session_state.user_debate_time
|
944 |
+
# average_word_per_time = total_word_count / st.session_state.debate_time # ์๊ฐ ๋จ์๋ณด๊ณ ๋์ค์ ์์ ํ๊ธฐ
|
945 |
+
# st.write("Average Word Per Time: ", average_word_per_time)
|
946 |
+
|
947 |
+
# # 2. ๋น์ถ ๋จ์ด: ๋ฐ๋ณตํด์ ์ฌ์ฉํ๋ ๋จ์ด ๋ฆฌ์คํธ
|
948 |
+
# # ๋น๋ ๊ณ์ฐ
|
949 |
+
# frequency = Counter(user_history)
|
950 |
+
# # ๊ฐ์ฅ ๋น๋๊ฐ ๋์ ๋ฐ์ดํฐ ์ถ๋ ฅ
|
951 |
+
# most_common_data = frequency.most_common(10)
|
952 |
+
#
|
953 |
+
# print(most_common_data)
|
954 |
+
# st.write("Most Common Words: ", most_common_data)
|
955 |
+
|
956 |
+
# # 3. ๋ฐํ ์ต๊ด: ๋ถํ์ํ ์ธ์ด์ต๊ด(์, ์)
|
957 |
+
# # whisper preprocesser์์ ์ฃผ๋ฉด
|
958 |
+
# disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
|
959 |
+
# # Count the disfluency words
|
960 |
+
# disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
961 |
+
# st.write("Disfluency Counts: ", disfluency_counts)
|
962 |
+
|
963 |
+
# if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
|
964 |
+
# put_item(
|
965 |
+
# table=dynamodb.Table('DEBO_evaluation'),
|
966 |
+
# item={
|
967 |
+
# 'user_id': st.session_state.user_id,
|
968 |
+
# 'time_stamp': time_stamp,
|
969 |
+
# 'total_word_count': total_word_count,
|
970 |
+
# 'average_word_per_time': Decimal(str(average_word_per_time)),
|
971 |
+
# 'disfluency_counts': disfluency_counts,
|
972 |
+
# 'session_num': int(st.session_state.session_num),
|
973 |
+
# }
|
974 |
+
# )
|
975 |
|
976 |
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
977 |
# st.session_state.debate_history
|
|
|
994 |
"Page 4": page4, # ํ ๋ก ์ธ๋ถ์ฌํญ ์ค์
|
995 |
"Page 5": page5, # Total Debate
|
996 |
"Page 6": page6, # Evaluation Only
|
997 |
+
# "Page 7": page7, # Analyzing Utterances
|
998 |
}
|
999 |
|
1000 |
selection = st.session_state.page
|
1001 |
+
#TODO delete!
|
1002 |
print("selection:", selection)
|
1003 |
|
1004 |
page = pages[selection]
|
1005 |
# Execute selected page function
|
1006 |
page()
|
|
|
|