Ridealist commited on
Commit
cbe6146
โ€ข
1 Parent(s): 8d88728

refactor: diabled 'ONLY' Utterance/Debate Judgement Anlaysis function

Browse files
Files changed (1) hide show
  1. app.py +124 -112
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 page_6_7_controller():
128
- st.session_state.page = "Page 7"
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
- error_message = st.empty()
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
- error_message.error('Please fill in correct User ID')
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
- page_control_func = page_2_7_controller
 
 
211
 
212
  st.button(
213
  label='Next',
214
  type='primary',
215
- on_click=page_control_func
 
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
- # end time
858
- st.session_state.end_time = time.time()
859
- st.session_state.debate_time = st.session_state.end_time - st.session_state.start_time
860
 
861
- _, _, pre, home = st.columns([5, 5, 1, 1])
862
- with pre:
863
- st.button("๐Ÿ”™", on_click=page_1_2_controller, use_container_width=True)
864
- with home:
865
- st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
866
 
867
- st.header('Total Debate Evaluation')
868
 
869
- tab1, tab2 = st.tabs(['Debate Judgement', 'Debate Analysis'])
870
 
871
- with tab1:
872
- st.header("Debate Evaluation")
873
 
874
- debate_themes = ['User-Bot', "User", "Bot"]
875
-
876
- # ์ „์ฒด, ์œ ์ €, ๋ด‡ ์„ธ ๊ฐ€์ง€ ์˜ต์…˜ ์ค‘์— ์„ ํƒ
877
- judgement_who = st.selectbox("Choose your debate theme", debate_themes)
878
-
879
- if st.session_state.judgement_result == "":
880
- with st.spinner('Wait for judgement result...'):
881
- judgement_result = ""
882
-
883
- user_debate_history = "".join(
884
- st.session_state.user_debate_history
885
- )
886
- bot_debate_history = "".join(
887
- st.session_state.bot_debate_history
888
- )
889
-
890
- judgement_result = debate_judgement(
891
- judgement_who,
892
- user_debate_history,
893
- bot_debate_history
894
- )
895
 
896
- st.session_state.judgement_result = judgement_result
897
 
898
- st.write("Debate Judgement Result")
899
- st.write(judgement_result)
900
-
901
- if judgement_result:
902
- put_item(
903
- table=dynamodb.Table('DEBO_evaluation'),
904
- item={
905
- 'user_id': st.session_state.user_id,
906
- 'time_stamp': time_stamp,
907
- 'judgement_text': judgement_result,
908
- 'session_num': int(st.session_state.session_num),
909
- }
910
- )
911
- st.success('Done!')
912
- else:
913
- st.write(st.session_state.judgement_result)
914
-
915
- with tab2:
916
- st.header('Debate Analysis')
917
-
918
- # ์œ ์ €์˜ history๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐœํ™”๋Ÿ‰, ๋นˆ์ถœ ๋‹จ์–ด, ๋ฐœํ™” ์Šต๊ด€ ์„ธ ๊ฐ€์ง€๋ฅผ ๋ถ„์„
919
- user_history = st.session_state.user_debate_history
920
-
921
- # 1. ๋ฐœํ™”๋Ÿ‰: ์ด ๋‹จ์–ด, ํ‰๊ท  ์†๋„(๋‹จ์–ด/์‹œ๊ฐ„)๋ฅผ ํ‰๊ท  ๋ฐœํ™”๋Ÿ‰ ํ˜น์€ ์ฐธ๊ณ  ์ง€ํ‘œ์™€ ๋น„๊ตํ•ด ์ œ์‹œ
922
-
923
- # ์ด ๋‹จ์–ด
924
- # ํ…์ŠคํŠธ๋ฅผ ๋‹จ์–ด๋กœ ๋ถ„ํ• ํ•ฉ๋‹ˆ๋‹ค.
925
- # ๊ฐ ๋‹จ์–ด์˜ ๋นˆ๋„๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
926
- total_word_count = len(user_history)
927
- #total_word_count = len(user_history.split())
928
- st.write("Total Word Count: ", total_word_count)
929
-
930
- # ํ‰๊ท  ์†๋„(๋‹จ์–ด/์‹œ๊ฐ„)
931
- #user_debate_time = st.session_state.user_debate_time
932
- average_word_per_time = total_word_count / st.session_state.debate_time # ์‹œ๊ฐ„ ๋‹จ์œ„๋ณด๊ณ  ๋‚˜์ค‘์— ์ˆ˜์ •ํ•˜๊ธฐ
933
- st.write("Average Word Per Time: ", average_word_per_time)
934
-
935
- # 2. ๋นˆ์ถœ ๋‹จ์–ด: ๋ฐ˜๋ณตํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋‹จ์–ด ๋ฆฌ์ŠคํŠธ
936
- # ๋นˆ๋„ ๊ณ„์‚ฐ
937
- frequency = Counter(user_history)
938
- # ๊ฐ€์žฅ ๋นˆ๋„๊ฐ€ ๋†’์€ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ
939
- most_common_data = frequency.most_common(10)
940
- print(most_common_data)
941
- st.write("Most Common Words: ", most_common_data)
942
-
943
- # 3. ๋ฐœํ™” ์Šต๊ด€: ๋ถˆํ•„์š”ํ•œ ์–ธ์–ด์Šต๊ด€(์•„, ์Œ)
944
- # whisper preprocesser์—์„œ ์ฃผ๋ฉด
945
- disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
946
- # Count the disfluency words
947
- disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
948
- st.write("Disfluency Counts: ", disfluency_counts)
949
-
950
- if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
951
- put_item(
952
- table=dynamodb.Table('DEBO_evaluation'),
953
- item={
954
- 'user_id': st.session_state.user_id,
955
- 'time_stamp': time_stamp,
956
- 'total_word_count': total_word_count,
957
- 'average_word_per_time': Decimal(str(average_word_per_time)),
958
- 'disfluency_counts': disfluency_counts,
959
- 'session_num': int(st.session_state.session_num),
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()