Spaces:
Runtime error
Runtime error
Revert "refactor: disconnect DynomoDB module"
Browse filesThis reverts commit 3bcbe7ac72c79a1b4945d2c75f7898dccb071b5b.
app.py
CHANGED
@@ -4,6 +4,7 @@ import pprint
|
|
4 |
import time
|
5 |
import openai
|
6 |
|
|
|
7 |
from gtts import gTTS
|
8 |
from collections import Counter
|
9 |
from streamlit_chat import message
|
@@ -11,6 +12,7 @@ from audiorecorder import audiorecorder
|
|
11 |
|
12 |
# internal modules
|
13 |
from bots.judgement_bot import debate_judgement
|
|
|
14 |
from modules.gpt_modules import gpt_call, gpt_call_context
|
15 |
from modules.whisper_modules import whisper_transcribe
|
16 |
from modules.setting_modules import blockPrint
|
@@ -25,6 +27,11 @@ blockPrint()
|
|
25 |
#########################################################
|
26 |
st.set_page_config(page_title="Debate With GPT : DEBO")
|
27 |
|
|
|
|
|
|
|
|
|
|
|
28 |
#########################################################
|
29 |
# Time Stamp
|
30 |
#########################################################
|
@@ -154,10 +161,18 @@ def save_info(user_id):
|
|
154 |
#########################################################
|
155 |
# Session Update
|
156 |
#########################################################
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
def page1():
|
163 |
val_id = False
|
@@ -300,6 +315,19 @@ def store_debate_data(checked, case1, case2, case3):
|
|
300 |
if not checked:
|
301 |
st.session_state.case1, st.session_state.case2, st.session_state.case3 = case1, case2, case3
|
302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
def page4():
|
305 |
#########################################################
|
@@ -470,6 +498,18 @@ def page4():
|
|
470 |
st.experimental_rerun()
|
471 |
st.stop()
|
472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
else:
|
474 |
result = st.session_state.ask_gpt_prev_response
|
475 |
|
@@ -545,6 +585,16 @@ def page5():
|
|
545 |
st.experimental_rerun()
|
546 |
st.stop()
|
547 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
548 |
else:
|
549 |
result = st.session_state.ask_gpt_prev_response
|
550 |
|
@@ -642,8 +692,29 @@ def page5():
|
|
642 |
st.experimental_rerun()
|
643 |
st.stop()
|
644 |
st.session_state['pre_audio'] = audio
|
645 |
-
turn_num = 0
|
646 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
647 |
else:
|
648 |
send_error_message.error("Please record your voice first", icon="๐จ")
|
649 |
reload = True
|
@@ -759,6 +830,16 @@ def page6():
|
|
759 |
st.write("Debate Judgement Result")
|
760 |
st.write(judgement_result)
|
761 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
762 |
st.success('Done!')
|
763 |
else:
|
764 |
st.write(st.session_state.judgement_result)
|
@@ -829,6 +910,20 @@ def page6():
|
|
829 |
disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
830 |
st.write("Disfluency Counts: ", disfluency_counts)
|
831 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
832 |
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
833 |
# st.session_state.debate_history
|
834 |
|
|
|
4 |
import time
|
5 |
import openai
|
6 |
|
7 |
+
from decimal import Decimal
|
8 |
from gtts import gTTS
|
9 |
from collections import Counter
|
10 |
from streamlit_chat import message
|
|
|
12 |
|
13 |
# internal modules
|
14 |
from bots.judgement_bot import debate_judgement
|
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 |
from modules.setting_modules import blockPrint
|
|
|
27 |
#########################################################
|
28 |
st.set_page_config(page_title="Debate With GPT : DEBO")
|
29 |
|
30 |
+
#########################################################
|
31 |
+
# GET DB
|
32 |
+
#########################################################
|
33 |
+
dynamodb = get_db()
|
34 |
+
|
35 |
#########################################################
|
36 |
# Time Stamp
|
37 |
#########################################################
|
|
|
161 |
#########################################################
|
162 |
# Session Update
|
163 |
#########################################################
|
164 |
+
debate_setting = get_lastest_item(
|
165 |
+
table=dynamodb.Table('DEBO_debate_setting'),
|
166 |
+
name_of_partition_key="user_id",
|
167 |
+
value_of_partition_key=st.session_state.user_id,
|
168 |
+
limit_num=1
|
169 |
+
)
|
170 |
+
# Session์ด ์๋ค๋ฉด, 0์ผ๋ก ์ด๊ธฐํ
|
171 |
+
if not debate_setting:
|
172 |
+
st.session_state.session_num = 0
|
173 |
+
# User์ ์ด์ ๊ธฐ๋ก์์ Session์ด ์๋ค๋ฉด, Session Number๋ฅผ ๊ฐ์ ธ์ค๊ณ ๊ฐฑ์ ํจ
|
174 |
+
else:
|
175 |
+
st.session_state.session_num = debate_setting[0]['session_num']
|
176 |
|
177 |
def page1():
|
178 |
val_id = False
|
|
|
315 |
if not checked:
|
316 |
st.session_state.case1, st.session_state.case2, st.session_state.case3 = case1, case2, case3
|
317 |
|
318 |
+
put_item(
|
319 |
+
table=dynamodb.Table('DEBO_debate_setting'),
|
320 |
+
item={
|
321 |
+
'user_id': st.session_state.user_id,
|
322 |
+
'time_stamp': time_stamp,
|
323 |
+
'debate_theme': st.session_state.debate_theme,
|
324 |
+
'debate_topic': st.session_state.topic,
|
325 |
+
'case1': st.session_state.case1,
|
326 |
+
'case2': st.session_state.case2,
|
327 |
+
'case3': st.session_state.case3,
|
328 |
+
'session_num': st.session_state.session_num,
|
329 |
+
}
|
330 |
+
)
|
331 |
|
332 |
def page4():
|
333 |
#########################################################
|
|
|
498 |
st.experimental_rerun()
|
499 |
st.stop()
|
500 |
|
501 |
+
# save user_prompt and bot_response to database
|
502 |
+
put_item(
|
503 |
+
table=dynamodb.Table('DEBO_gpt_ask'),
|
504 |
+
item={
|
505 |
+
'user_id': st.session_state.user_id,
|
506 |
+
'time_stamp': time_stamp,
|
507 |
+
'user_prompt': user_input,
|
508 |
+
'bot_response': result,
|
509 |
+
'session_num': st.session_state.session_num,
|
510 |
+
}
|
511 |
+
)
|
512 |
+
|
513 |
else:
|
514 |
result = st.session_state.ask_gpt_prev_response
|
515 |
|
|
|
585 |
st.experimental_rerun()
|
586 |
st.stop()
|
587 |
|
588 |
+
put_item(
|
589 |
+
table=dynamodb.Table('DEBO_gpt_ask'),
|
590 |
+
item={
|
591 |
+
'user_id': st.session_state.user_id,
|
592 |
+
'time_stamp': time_stamp,
|
593 |
+
'user_prompt': user_input,
|
594 |
+
'bot_response': result,
|
595 |
+
'session_num': st.session_state.session_num,
|
596 |
+
}
|
597 |
+
)
|
598 |
else:
|
599 |
result = st.session_state.ask_gpt_prev_response
|
600 |
|
|
|
692 |
st.experimental_rerun()
|
693 |
st.stop()
|
694 |
st.session_state['pre_audio'] = audio
|
|
|
695 |
|
696 |
+
debate_main_latest_data = get_lastest_item(
|
697 |
+
table=dynamodb.Table('DEBO_debate_main'),
|
698 |
+
name_of_partition_key="user_id",
|
699 |
+
value_of_partition_key=st.session_state.user_id,
|
700 |
+
limit_num=1
|
701 |
+
)
|
702 |
+
if not debate_main_latest_data:
|
703 |
+
turn_num = 0
|
704 |
+
else:
|
705 |
+
turn_num = debate_main_latest_data[0]['turn_num']
|
706 |
+
|
707 |
+
put_item(
|
708 |
+
table=dynamodb.Table('DEBO_debate_main'),
|
709 |
+
item={
|
710 |
+
'user_id': st.session_state.user_id,
|
711 |
+
'time_stamp': time_stamp,
|
712 |
+
'session_num': st.session_state.session_num,
|
713 |
+
'bot_response': response,
|
714 |
+
'user_prompt': user_input,
|
715 |
+
'turn_num': turn_num,
|
716 |
+
}
|
717 |
+
)
|
718 |
else:
|
719 |
send_error_message.error("Please record your voice first", icon="๐จ")
|
720 |
reload = True
|
|
|
830 |
st.write("Debate Judgement Result")
|
831 |
st.write(judgement_result)
|
832 |
|
833 |
+
if judgement_result != "":
|
834 |
+
put_item(
|
835 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
836 |
+
item={
|
837 |
+
'user_id': st.session_state.user_id,
|
838 |
+
'time_stamp': time_stamp,
|
839 |
+
'judgement_text': judgement_result,
|
840 |
+
'session_num': st.session_state.session_num,
|
841 |
+
}
|
842 |
+
)
|
843 |
st.success('Done!')
|
844 |
else:
|
845 |
st.write(st.session_state.judgement_result)
|
|
|
910 |
disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
911 |
st.write("Disfluency Counts: ", disfluency_counts)
|
912 |
|
913 |
+
if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
|
914 |
+
|
915 |
+
put_item(
|
916 |
+
table=dynamodb.Table('DEBO_debate_analysis'),
|
917 |
+
item={
|
918 |
+
'user_id': st.session_state.user_id,
|
919 |
+
'time_stamp': time_stamp,
|
920 |
+
'total_word_count': total_word_count,
|
921 |
+
'average_word_per_time': Decimal(str(average_word_per_time)),
|
922 |
+
'disfluency_counts': disfluency_counts,
|
923 |
+
'session_num': int(st.session_state.session_num),
|
924 |
+
}
|
925 |
+
)
|
926 |
+
|
927 |
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
928 |
# st.session_state.debate_history
|
929 |
|