Ridealist commited on
Commit
531458e
โ€ข
1 Parent(s): baa5cb8

feat: Apply comments for non-MVP features & apply block Print setting

Browse files
Files changed (1) hide show
  1. app.py +78 -90
app.py CHANGED
@@ -11,29 +11,31 @@ from audiorecorder import audiorecorder
11
 
12
  # internal modules
13
  from bots.judgement_bot import debate_judgement
14
- from bots.perfect_case_bot import perfect_case_selector
15
  from modules.db_modules import get_db, put_item, get_all_items, get_lastest_item
16
  from modules.gpt_modules import gpt_call, gpt_call_context
17
  from modules.whisper_modules import whisper_transcribe
 
18
 
 
 
 
 
19
 
20
  #########################################################
21
  # GET DB
22
  #########################################################
23
  dynamodb = get_db()
24
 
25
-
26
  #########################################################
27
  # Time Stamp
28
  #########################################################
29
  tm = time.localtime()
30
  time_stamp = time.strftime('%Y-%m-%d %I:%M:%S %p', tm)
31
 
32
-
33
  #########################################################
34
  # Page Configurations
35
  #########################################################
36
- st.set_page_config(page_title="Streamlit App")
37
 
38
  #########################################################
39
  # Initialize session state variables
@@ -71,9 +73,6 @@ if "user_debate_history" not in st.session_state:
71
  if "bot_debate_history" not in st.session_state:
72
  st.session_state.bot_debate_history = []
73
 
74
- if "user_debate_time" not in st.session_state:
75
- st.session_state.user_debate_time = ""
76
-
77
  if "pros_and_cons" not in st.session_state:
78
  st.session_state.pros_and_cons = ""
79
 
@@ -86,35 +85,31 @@ if "end_time" not in st.session_state:
86
  if "debate_time" not in st.session_state:
87
  st.session_state.debate_time = 0
88
 
 
 
 
89
  if "pre_audio" not in st.session_state:
90
  st.session_state.pre_audio = np.array([])
91
 
92
  if "disabled" not in st.session_state:
93
  st.session_state.disabled = True
94
 
95
-
96
  # for db session number
97
  if "session_num" not in st.session_state:
98
  st.session_state.session_num = 0
99
 
100
- if "judgement_result" not in st.session_state:
101
- st.session_state.judgement_result = ""
102
-
103
  #########################################################
104
  # Page Controller
105
  #########################################################
106
  def page_1_2_controller():
107
  st.session_state.page = "Page 2"
108
 
109
- def page_2_3_controller():
110
- st.session_state.page = "Page 3"
111
-
112
- def page2_tab_controller():
113
- st.session_state.page2_tab = "tab2"
114
-
115
- def page_3_4_controller():
116
  st.session_state.page = "Page 4"
117
 
 
 
 
118
  def page_4_5_controller():
119
  st.session_state.page = "Page 5"
120
 
@@ -127,6 +122,9 @@ def page_5_6_controller():
127
  def page_n_1_controller():
128
  st.session_state.page = "Page 1"
129
 
 
 
 
130
  #########################################################
131
  # Page 1
132
  #########################################################
@@ -200,7 +198,7 @@ def page2():
200
 
201
  # add controller
202
  if option_result == "Total Debate":
203
- page_control_func = page_2_3_controller
204
  st.session_state.disabled = False
205
  elif option_result == "Evaluation Only & Analyzing Utterances":
206
  st.info('Sorry:( This function will be developed soon.', icon="โ„น๏ธ")
@@ -213,56 +211,52 @@ def page2():
213
  disabled=st.session_state.disabled,
214
  on_click=page_control_func,
215
  )
216
-
217
 
218
  #########################################################
219
  # Page 3
220
  #########################################################
221
- def page3():
222
- debate_history = get_lastest_item(
223
- table=dynamodb.Table('DEBO_debate_setting'),
224
- name_of_partition_key="user_id",
225
- value_of_partition_key=st.session_state.user_id,
226
- #TODO ์ „์ฒด ๋ณด์—ฌ์ค„ ๊ฐœ์ˆ˜ ์„ค์ •
227
- limit_num=10
228
- )
 
 
 
229
 
230
- if not debate_history:
231
- st.info('There is no previous debate history', icon="โ„น๏ธ")
232
-
233
- #TODO delete!
234
- print(debate_history)
235
-
236
- _, _, pre, home = st.columns([5, 5, 1, 1])
237
- with pre:
238
- st.button("๐Ÿ”™", on_click=page_1_2_controller, use_container_width=True)
239
- with home:
240
- st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
241
- st.header("Debate History")
242
-
243
- st.button(
244
- label=f'๐Ÿš€ Start new debate',
245
- type='primary',
246
- on_click=page_3_4_controller
247
- )
248
- st.write("_"*50)
249
-
250
- num_history = len(debate_history)
251
- for i in range(num_history):
252
- with st.container():
253
- st.write(f"#### {i + 1}")
254
- st.write(f"Debate Thema : {debate_history[i]['debate_theme']}")
255
- st.write(f"Debate Topic : {debate_history[i]['debate_topic']}")
256
- st.write(f"Case 1 : {debate_history[i]['case1']}")
257
- st.write(f"Case 2 : {debate_history[i]['case2']}")
258
- st.write(f"Case 3 : {debate_history[i]['case3']}")
259
- st.write(f"Created at : {debate_history[i]['time_stamp']}")
260
- st.button(
261
- label='Continue this dabate',
262
- key=str(i),
263
- on_click=page_4_5_controller
264
- )
265
- st.write("_"*50)
266
 
267
  #########################################################
268
  # Page 4
@@ -294,7 +288,7 @@ def page4():
294
 
295
  _, _, pre, home = st.columns([5, 5, 1, 1])
296
  with pre:
297
- st.button("๐Ÿ”™", on_click=page_2_3_controller, use_container_width=True)
298
  with home:
299
  st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
300
 
@@ -607,7 +601,7 @@ def page5():
607
 
608
  _, _, pre, home = st.columns([5, 5, 1, 1])
609
  with pre:
610
- st.button("๐Ÿ”™", on_click=page_3_4_controller, use_container_width=True)
611
  with home:
612
  st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
613
 
@@ -638,8 +632,6 @@ def page5():
638
 
639
  try :
640
  response = generate_response(user_input)
641
- #TODO delete
642
- print("response", response)
643
  except:
644
  openai_error_bottom.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="โš ๏ธ")
645
  time.sleep(1)
@@ -655,8 +647,6 @@ def page5():
655
  value_of_partition_key=st.session_state.user_id,
656
  limit_num=1
657
  )
658
- #TODO delete
659
- print(f'debate_main_latest_data : {debate_main_latest_data}')
660
  if not debate_main_latest_data:
661
  turn_num = 0
662
  else:
@@ -737,7 +727,7 @@ def page6():
737
 
738
  st.write('Note that evaluation using GPT is an experimental feature. Please check it out and give us your feedback.')
739
 
740
- tab1, tab2, tab3 = st.tabs(['Debate Evaluation', 'Perfect Case', 'Debate Analysis'])
741
 
742
  with tab1:
743
  st.header("Debate Evaluation")
@@ -778,30 +768,28 @@ def page6():
778
  else:
779
  st.write(st.session_state.judgement_result)
780
 
781
- with tab2:
782
- st.header("Perfect Case")
783
 
784
- perfect_case_list = [
785
- "This house supports the creation of an international court with a mandate to prosecute leaders for health crimes",
786
- "This house believes that governments would be justified in heavily pursuing long-termism",
787
- "THBT international discussion forums should not self-censor* in an attempt to increase inclusivity to people from countries with stringent freedom-of-speech rules.",
788
- ]
789
 
790
- perfect_case_selected = st.selectbox("Choose the Perfect Case", perfect_case_list)
791
 
792
- perfect_case = perfect_case_selector(
793
- perfect_case_selected
794
- )
795
 
796
- perfect_case_url = perfect_case['perfect_case_url']
797
- perfect_case_text = perfect_case['perfect_case_text']
798
-
799
- st.video(perfect_case_url)
800
 
801
- st.write(perfect_case_text)
 
802
 
803
-
804
- with tab3:
805
  st.header('Debate Analysis')
806
 
807
  # ์œ ์ €์˜ history๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐœํ™”๋Ÿ‰, ๋นˆ์ถœ ๋‹จ์–ด, ๋ฐœํ™” ์Šต๊ด€ ์„ธ ๊ฐ€์ง€๋ฅผ ๋ถ„์„
@@ -999,7 +987,7 @@ def page6():
999
  pages = {
1000
  "Page 1": page1, # user_id๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š” ํŽ˜์ด์ง€
1001
  "Page 2": page2, # ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜๋Š” ํŽ˜์ด์ง€
1002
- "Page 3": page3, # ๊ณผ๊ฑฐ ํ† ๋ก  ๋‚ด์—ญ์„ ์„ ํƒํ•˜๋Š” ํŽ˜์ด์ง€
1003
  "Page 4": page4, # ํ† ๋ก  ์„ธ๋ถ€์‚ฌํ•ญ ์„ค์ •
1004
  "Page 5": page5, # Total Debate
1005
  "Page 6": page6, # Evaluation Only
 
11
 
12
  # internal modules
13
  from bots.judgement_bot import debate_judgement
 
14
  from modules.db_modules import get_db, put_item, get_all_items, get_lastest_item
15
  from modules.gpt_modules import gpt_call, gpt_call_context
16
  from modules.whisper_modules import whisper_transcribe
17
+ from modules.setting_modules import blockPrint
18
 
19
+ #########################################################
20
+ # Disabled Console print
21
+ #########################################################
22
+ blockPrint()
23
 
24
  #########################################################
25
  # GET DB
26
  #########################################################
27
  dynamodb = get_db()
28
 
 
29
  #########################################################
30
  # Time Stamp
31
  #########################################################
32
  tm = time.localtime()
33
  time_stamp = time.strftime('%Y-%m-%d %I:%M:%S %p', tm)
34
 
 
35
  #########################################################
36
  # Page Configurations
37
  #########################################################
38
+ st.set_page_config(page_title="Debate With GPT : DEBO")
39
 
40
  #########################################################
41
  # Initialize session state variables
 
73
  if "bot_debate_history" not in st.session_state:
74
  st.session_state.bot_debate_history = []
75
 
 
 
 
76
  if "pros_and_cons" not in st.session_state:
77
  st.session_state.pros_and_cons = ""
78
 
 
85
  if "debate_time" not in st.session_state:
86
  st.session_state.debate_time = 0
87
 
88
+ if "judgement_result" not in st.session_state:
89
+ st.session_state.judgement_result = ""
90
+
91
  if "pre_audio" not in st.session_state:
92
  st.session_state.pre_audio = np.array([])
93
 
94
  if "disabled" not in st.session_state:
95
  st.session_state.disabled = True
96
 
 
97
  # for db session number
98
  if "session_num" not in st.session_state:
99
  st.session_state.session_num = 0
100
 
 
 
 
101
  #########################################################
102
  # Page Controller
103
  #########################################################
104
  def page_1_2_controller():
105
  st.session_state.page = "Page 2"
106
 
107
+ def page_2_4_controller():
 
 
 
 
 
 
108
  st.session_state.page = "Page 4"
109
 
110
+ # def page_3_4_controller():
111
+ # st.session_state.page = "Page 4"
112
+
113
  def page_4_5_controller():
114
  st.session_state.page = "Page 5"
115
 
 
122
  def page_n_1_controller():
123
  st.session_state.page = "Page 1"
124
 
125
+ def page2_tab_controller():
126
+ st.session_state.page2_tab = "tab2"
127
+
128
  #########################################################
129
  # Page 1
130
  #########################################################
 
198
 
199
  # add controller
200
  if option_result == "Total Debate":
201
+ page_control_func = page_2_4_controller
202
  st.session_state.disabled = False
203
  elif option_result == "Evaluation Only & Analyzing Utterances":
204
  st.info('Sorry:( This function will be developed soon.', icon="โ„น๏ธ")
 
211
  disabled=st.session_state.disabled,
212
  on_click=page_control_func,
213
  )
 
214
 
215
  #########################################################
216
  # Page 3
217
  #########################################################
218
+ # def page3():
219
+ # debate_history = get_lastest_item(
220
+ # table=dynamodb.Table('DEBO_debate_setting'),
221
+ # name_of_partition_key="user_id",
222
+ # value_of_partition_key=st.session_state.user_id,
223
+ # #TODO ์ „์ฒด ๋ณด์—ฌ์ค„ ๊ฐœ์ˆ˜ ์„ค์ •
224
+ # limit_num=10
225
+ # )
226
+
227
+ # if not debate_history:
228
+ # st.info('There is no previous debate history', icon="โ„น๏ธ")
229
 
230
+ # _, _, pre, home = st.columns([5, 5, 1, 1])
231
+ # with pre:
232
+ # st.button("๐Ÿ”™", on_click=page_1_2_controller, use_container_width=True)
233
+ # with home:
234
+ # st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
235
+ # st.header("Debate History")
236
+
237
+ # st.button(
238
+ # label=f'๐Ÿš€ Start new debate',
239
+ # type='primary',
240
+ # on_click=page_3_4_controller
241
+ # )
242
+ # st.write("_"*50)
243
+
244
+ # num_history = len(debate_history)
245
+ # for i in range(num_history):
246
+ # with st.container():
247
+ # st.write(f"#### {i + 1}")
248
+ # st.write(f"Debate Thema : {debate_history[i]['debate_theme']}")
249
+ # st.write(f"Debate Topic : {debate_history[i]['debate_topic']}")
250
+ # st.write(f"Case 1 : {debate_history[i]['case1']}")
251
+ # st.write(f"Case 2 : {debate_history[i]['case2']}")
252
+ # st.write(f"Case 3 : {debate_history[i]['case3']}")
253
+ # st.write(f"Created at : {debate_history[i]['time_stamp']}")
254
+ # st.button(
255
+ # label='Continue this dabate',
256
+ # key=str(i),
257
+ # on_click=page_4_5_controller
258
+ # )
259
+ # st.write("_"*50)
 
 
 
 
 
 
260
 
261
  #########################################################
262
  # Page 4
 
288
 
289
  _, _, pre, home = st.columns([5, 5, 1, 1])
290
  with pre:
291
+ st.button("๐Ÿ”™", on_click=page_1_2_controller, use_container_width=True)
292
  with home:
293
  st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
294
 
 
601
 
602
  _, _, pre, home = st.columns([5, 5, 1, 1])
603
  with pre:
604
+ st.button("๐Ÿ”™", on_click=page_2_4_controller, use_container_width=True)
605
  with home:
606
  st.button("๐Ÿ”", on_click=page_n_1_controller, use_container_width=True)
607
 
 
632
 
633
  try :
634
  response = generate_response(user_input)
 
 
635
  except:
636
  openai_error_bottom.warning('Chat-GPT Error : The engine is currently overloaded. Please click Rerun button in a second', icon="โš ๏ธ")
637
  time.sleep(1)
 
647
  value_of_partition_key=st.session_state.user_id,
648
  limit_num=1
649
  )
 
 
650
  if not debate_main_latest_data:
651
  turn_num = 0
652
  else:
 
727
 
728
  st.write('Note that evaluation using GPT is an experimental feature. Please check it out and give us your feedback.')
729
 
730
+ tab1, tab2 = st.tabs(['Debate Evaluation', 'Debate Analysis']) ## Delete 'Perfect Case'
731
 
732
  with tab1:
733
  st.header("Debate Evaluation")
 
768
  else:
769
  st.write(st.session_state.judgement_result)
770
 
771
+ # with tab2:
772
+ # st.header("Perfect Case")
773
 
774
+ # perfect_case_list = [
775
+ # "This house supports the creation of an international court with a mandate to prosecute leaders for health crimes",
776
+ # "This house believes that governments would be justified in heavily pursuing long-termism",
777
+ # "THBT international discussion forums should not self-censor* in an attempt to increase inclusivity to people from countries with stringent freedom-of-speech rules.",
778
+ # ]
779
 
780
+ # perfect_case_selected = st.selectbox("Choose the Perfect Case", perfect_case_list)
781
 
782
+ # perfect_case = perfect_case_selector(
783
+ # perfect_case_selected
784
+ # )
785
 
786
+ # perfect_case_url = perfect_case['perfect_case_url']
787
+ # perfect_case_text = perfect_case['perfect_case_text']
 
 
788
 
789
+ # st.video(perfect_case_url)
790
+ # st.write(perfect_case_text)
791
 
792
+ with tab2:
 
793
  st.header('Debate Analysis')
794
 
795
  # ์œ ์ €์˜ history๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐœํ™”๋Ÿ‰, ๋นˆ์ถœ ๋‹จ์–ด, ๋ฐœํ™” ์Šต๊ด€ ์„ธ ๊ฐ€์ง€๋ฅผ ๋ถ„์„
 
987
  pages = {
988
  "Page 1": page1, # user_id๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š” ํŽ˜์ด์ง€
989
  "Page 2": page2, # ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜๋Š” ํŽ˜์ด์ง€
990
+ # "Page 3": page3, # ๊ณผ๊ฑฐ ํ† ๋ก  ๋‚ด์—ญ์„ ์„ ํƒํ•˜๋Š” ํŽ˜์ด์ง€
991
  "Page 4": page4, # ํ† ๋ก  ์„ธ๋ถ€์‚ฌํ•ญ ์„ค์ •
992
  "Page 5": page5, # Total Debate
993
  "Page 6": page6, # Evaluation Only