Spaces:
Runtime error
Runtime error
feat: Apply comments for non-MVP features & apply block Print setting
Browse files
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="
|
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
|
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 =
|
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 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
229 |
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
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=
|
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=
|
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
|
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 |
-
|
783 |
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
|
790 |
-
|
791 |
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
st.video(perfect_case_url)
|
800 |
|
801 |
-
|
|
|
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
|