Spaces:
Runtime error
Runtime error
codingchild
commited on
Commit
•
5288426
1
Parent(s):
d19da7b
add new
Browse files- app.py +91 -73
- bots/judgement_bot.py +5 -43
- bots/perfect_case_bot.py +66 -0
app.py
CHANGED
@@ -8,6 +8,7 @@ from collections import Counter
|
|
8 |
from streamlit_chat import message
|
9 |
|
10 |
from bots.judgement_bot import debate_judgement
|
|
|
11 |
import time
|
12 |
from time import strftime
|
13 |
|
@@ -93,6 +94,9 @@ if "pre_audio" not in st.session_state:
|
|
93 |
if "session_num" not in st.session_state:
|
94 |
st.session_state.session_num = 0
|
95 |
|
|
|
|
|
|
|
96 |
|
97 |
#########################################################
|
98 |
# Save function (placeholder)
|
@@ -468,9 +472,9 @@ def generate_response(prompt):
|
|
468 |
def execute_stt(audio, error_message):
|
469 |
|
470 |
# audio 기록 누적
|
471 |
-
user_audio_path = "audio/" + str(st.session_state.user_id) + "_" + str(st.session_state.session_num) + "_" + str(time.time()) + ".wav"
|
472 |
# audio 기록을 누적하고 싶지 않다면
|
473 |
-
|
474 |
|
475 |
wav_file = open(user_audio_path, "wb")
|
476 |
wav_file.write(audio.tobytes())
|
@@ -688,48 +692,59 @@ def page6():
|
|
688 |
|
689 |
st.write('Note that evaluation using GPT is an experimental feature. Please check it out and give us your feedback.')
|
690 |
|
691 |
-
tab1, tab2 = st.tabs(['Debate Evaluation', 'Debate Analysis'])
|
692 |
|
693 |
with tab1:
|
694 |
st.header("Debate Evaluation")
|
695 |
-
|
696 |
-
debate_themes = ['User-Bot', "User", "Bot"]
|
697 |
|
698 |
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
699 |
-
judgement_who = st.selectbox("Choose
|
700 |
|
701 |
-
|
702 |
-
|
|
|
703 |
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
)
|
710 |
-
|
711 |
-
judgement_result = debate_judgement(
|
712 |
-
judgement_who,
|
713 |
-
user_debate_history,
|
714 |
-
bot_debate_history
|
715 |
)
|
716 |
|
717 |
-
|
718 |
-
|
|
|
|
|
719 |
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
'
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
|
|
|
|
|
|
|
|
|
|
731 |
|
732 |
with tab2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
733 |
st.header('Debate Analysis')
|
734 |
|
735 |
# 유저의 history를 기반으로 발화량, 빈출 단어, 발화 습관 세 가지를 분석
|
@@ -740,10 +755,10 @@ def page6():
|
|
740 |
# 총 단어
|
741 |
# 텍스트를 단어로 분할합니다.
|
742 |
# 각 단어의 빈도를 계산합니다.
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
#total_word_count = len(user_history.split())
|
748 |
st.write("Total Word Count: ", total_word_count)
|
749 |
|
@@ -754,11 +769,16 @@ def page6():
|
|
754 |
|
755 |
# 2. 빈출 단어: 반복해서 사용하는 단어 리스트
|
756 |
# 빈도 계산
|
757 |
-
frequency = Counter(
|
758 |
# 가장 빈도가 높은 데이터 출력
|
759 |
-
most_common_data = frequency.most_common(
|
760 |
-
|
761 |
-
st.write("Most Common Words: "
|
|
|
|
|
|
|
|
|
|
|
762 |
|
763 |
# 3. 발화 습관: 불필요한 언어습관(아, 음)
|
764 |
# whisper preprocesser에서 주면
|
@@ -768,13 +788,6 @@ def page6():
|
|
768 |
st.write("Disfluency Counts: ", disfluency_counts)
|
769 |
|
770 |
if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
|
771 |
-
|
772 |
-
print("user_id", type(st.session_state.user_id))
|
773 |
-
print("time_stamp", type(time_stamp))
|
774 |
-
print("total_word_count", type(total_word_count))
|
775 |
-
print("average_word_per_time", type(average_word_per_time))
|
776 |
-
print("disfluency_counts", type(disfluency_counts))
|
777 |
-
print("session_num", type(st.session_state.session_num))
|
778 |
|
779 |
put_item(
|
780 |
table=dynamodb.Table('DEBO_debate_analysis'),
|
@@ -820,36 +833,41 @@ def page7():
|
|
820 |
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
821 |
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
822 |
|
823 |
-
|
824 |
-
|
|
|
825 |
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
)
|
832 |
-
|
833 |
-
judgement_result = debate_judgement(
|
834 |
-
judgement_who,
|
835 |
-
user_debate_history,
|
836 |
-
bot_debate_history
|
837 |
)
|
838 |
-
|
839 |
-
st.write("Debate Judgement Result")
|
840 |
-
st.write(judgement_result)
|
841 |
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
'user_id': st.session_state.user_id,
|
847 |
-
'time_stamp': time_stamp,
|
848 |
-
'judgement_text': judgement_result,
|
849 |
-
'session_num': int(st.session_state.session_num),
|
850 |
-
}
|
851 |
)
|
852 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
853 |
|
854 |
with tab2:
|
855 |
st.header('Debate Analysis')
|
|
|
8 |
from streamlit_chat import message
|
9 |
|
10 |
from bots.judgement_bot import debate_judgement
|
11 |
+
from bots.perfect_case_bot import perfect_case_selector
|
12 |
import time
|
13 |
from time import strftime
|
14 |
|
|
|
94 |
if "session_num" not in st.session_state:
|
95 |
st.session_state.session_num = 0
|
96 |
|
97 |
+
if "judgement_result" not in st.session_state:
|
98 |
+
st.session_state.judgement_result = ""
|
99 |
+
|
100 |
|
101 |
#########################################################
|
102 |
# Save function (placeholder)
|
|
|
472 |
def execute_stt(audio, error_message):
|
473 |
|
474 |
# audio 기록 누적
|
475 |
+
#user_audio_path = "audio/" + str(st.session_state.user_id) + "_" + str(st.session_state.session_num) + "_" + str(time.time()) + ".wav"
|
476 |
# audio 기록을 누적하고 싶지 않다면
|
477 |
+
user_audio_path = "audio/audio.wav"
|
478 |
|
479 |
wav_file = open(user_audio_path, "wb")
|
480 |
wav_file.write(audio.tobytes())
|
|
|
692 |
|
693 |
st.write('Note that evaluation using GPT is an experimental feature. Please check it out and give us your feedback.')
|
694 |
|
695 |
+
tab1, tab2, tab3 = st.tabs(['Debate Evaluation', 'Perfect Case', 'Debate Analysis'])
|
696 |
|
697 |
with tab1:
|
698 |
st.header("Debate Evaluation")
|
|
|
|
|
699 |
|
700 |
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
701 |
+
#judgement_who = st.selectbox("Choose what you want! (Evaluation result / Perfect case on this theme)", debate_themes)
|
702 |
|
703 |
+
if st.session_state.judgement_result == "":
|
704 |
+
with st.spinner('Wait for judgement result...'):
|
705 |
+
judgement_result = ""
|
706 |
|
707 |
+
user_debate_history = "".join(
|
708 |
+
st.session_state.user_debate_history
|
709 |
+
)
|
710 |
+
bot_debate_history = "".join(
|
711 |
+
st.session_state.bot_debate_history
|
|
|
|
|
|
|
|
|
|
|
|
|
712 |
)
|
713 |
|
714 |
+
judgement_result = debate_judgement(
|
715 |
+
user_debate_history,
|
716 |
+
bot_debate_history
|
717 |
+
)
|
718 |
|
719 |
+
st.write("Debate Judgement Result")
|
720 |
+
st.write(judgement_result)
|
721 |
+
|
722 |
+
if judgement_result != "":
|
723 |
+
put_item(
|
724 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
725 |
+
item={
|
726 |
+
'user_id': st.session_state.user_id,
|
727 |
+
'time_stamp': time_stamp,
|
728 |
+
'judgement_text': judgement_result,
|
729 |
+
'session_num': st.session_state.session_num,
|
730 |
+
}
|
731 |
+
)
|
732 |
+
st.success('Done!')
|
733 |
+
else:
|
734 |
+
st.write(st.session_state.judgement_result)
|
735 |
|
736 |
with tab2:
|
737 |
+
st.header("Perfect Case")
|
738 |
+
|
739 |
+
perfect_case = perfect_case_selector(
|
740 |
+
st.session_state.debate_theme,
|
741 |
+
st.session_state.topic
|
742 |
+
)
|
743 |
+
|
744 |
+
st.write(perfect_case)
|
745 |
+
|
746 |
+
|
747 |
+
with tab3:
|
748 |
st.header('Debate Analysis')
|
749 |
|
750 |
# 유저의 history를 기반으로 발화량, 빈출 단어, 발화 습관 세 가지를 분석
|
|
|
755 |
# 총 단어
|
756 |
# 텍스트를 단어로 분할합니다.
|
757 |
# 각 단어의 빈도를 계산합니다.
|
758 |
+
|
759 |
+
# 리스트를 문자열로 변환하고, 공백을 기준으로 단어를 분할합니다.
|
760 |
+
total_word_list = "".join(user_history).split()
|
761 |
+
total_word_count = len(total_word_list)
|
762 |
#total_word_count = len(user_history.split())
|
763 |
st.write("Total Word Count: ", total_word_count)
|
764 |
|
|
|
769 |
|
770 |
# 2. 빈출 단어: 반복해서 사용하는 단어 리스트
|
771 |
# 빈도 계산
|
772 |
+
frequency = Counter(total_word_list)
|
773 |
# 가장 빈도가 높은 데이터 출력
|
774 |
+
most_common_data = frequency.most_common(5)
|
775 |
+
|
776 |
+
st.write("Most Common Words: ")
|
777 |
+
for word, count in most_common_data:
|
778 |
+
st.write(" - ", word, ":", count)
|
779 |
+
|
780 |
+
# print(most_common_data)
|
781 |
+
# st.write("Most Common Words: ", most_common_data)
|
782 |
|
783 |
# 3. 발화 습관: 불필요한 언어습관(아, 음)
|
784 |
# whisper preprocesser에서 주면
|
|
|
788 |
st.write("Disfluency Counts: ", disfluency_counts)
|
789 |
|
790 |
if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
791 |
|
792 |
put_item(
|
793 |
table=dynamodb.Table('DEBO_debate_analysis'),
|
|
|
833 |
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
834 |
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
835 |
|
836 |
+
if st.session_state.judgement_result == "":
|
837 |
+
with st.spinner('Wait for judgement result...'):
|
838 |
+
judgement_result = ""
|
839 |
|
840 |
+
user_debate_history = "".join(
|
841 |
+
st.session_state.user_debate_history
|
842 |
+
)
|
843 |
+
bot_debate_history = "".join(
|
844 |
+
st.session_state.bot_debate_history
|
|
|
|
|
|
|
|
|
|
|
|
|
845 |
)
|
|
|
|
|
|
|
846 |
|
847 |
+
judgement_result = debate_judgement(
|
848 |
+
judgement_who,
|
849 |
+
user_debate_history,
|
850 |
+
bot_debate_history
|
|
|
|
|
|
|
|
|
|
|
851 |
)
|
852 |
+
|
853 |
+
st.session_state.judgement_result = judgement_result
|
854 |
+
|
855 |
+
st.write("Debate Judgement Result")
|
856 |
+
st.write(judgement_result)
|
857 |
+
|
858 |
+
if judgement_result:
|
859 |
+
put_item(
|
860 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
861 |
+
item={
|
862 |
+
'user_id': st.session_state.user_id,
|
863 |
+
'time_stamp': time_stamp,
|
864 |
+
'judgement_text': judgement_result,
|
865 |
+
'session_num': int(st.session_state.session_num),
|
866 |
+
}
|
867 |
+
)
|
868 |
+
st.success('Done!')
|
869 |
+
else:
|
870 |
+
st.write(st.session_state.judgement_result)
|
871 |
|
872 |
with tab2:
|
873 |
st.header('Debate Analysis')
|
bots/judgement_bot.py
CHANGED
@@ -2,33 +2,13 @@ from modules.gpt_modules import gpt_call
|
|
2 |
from langchain.prompts import PromptTemplate
|
3 |
|
4 |
def debate_judgement(
|
5 |
-
judgement_who,
|
6 |
user_debate_history,
|
7 |
bot_debate_history
|
8 |
):
|
9 |
-
|
10 |
-
if
|
11 |
-
|
12 |
-
|
13 |
-
"!!Instruction!",
|
14 |
-
"You are now the judge of this debate. Evaluate the debate according to the rules below.",
|
15 |
-
"Rule 1. Decide between the USER and BOT.",
|
16 |
-
"Rule 2. Summarize the debate as a whole and what each debater said.",
|
17 |
-
"Rule 3. For each debater, explain what was persuasive and what made the differnce between winning and losing.",
|
18 |
-
])
|
19 |
-
|
20 |
-
judgement_prompt = "\n".join([
|
21 |
-
judgement_prompt_preset,
|
22 |
-
"User: " + user_debate_history,
|
23 |
-
"Bot: " + bot_debate_history,
|
24 |
-
"Judgement must be logical with paragraphs.",
|
25 |
-
"Do not show Rule",
|
26 |
-
"Write judgement below.",
|
27 |
-
"Judgement: "
|
28 |
-
])
|
29 |
-
|
30 |
-
elif judgement_who == 'User':
|
31 |
-
|
32 |
judgement_prompt_preset = "\n".join([
|
33 |
"!!Instruction!",
|
34 |
"You are now the judge of this debate. Evaluate the debate according to the rules below.",
|
@@ -45,24 +25,6 @@ def debate_judgement(
|
|
45 |
"Judgement: "
|
46 |
])
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
judgement_prompt_preset = "\n".join([
|
51 |
-
"!!Instruction!",
|
52 |
-
"You are now the judge of this debate. Evaluate the debate according to the rules below.",
|
53 |
-
"Rule 1. Summarize the debate as a whole and each said.",
|
54 |
-
"Rule 2. Explain what was persuasive and what made the differnce between winning and losing.",
|
55 |
-
])
|
56 |
-
|
57 |
-
judgement_prompt = "\n".join([
|
58 |
-
judgement_prompt_preset,
|
59 |
-
"Bot: " + bot_debate_history,
|
60 |
-
"Judgement must be logical with paragraphs.",
|
61 |
-
"Do not show Rule",
|
62 |
-
"Write judgement below.",
|
63 |
-
"Judgement: "
|
64 |
-
])
|
65 |
-
|
66 |
-
bot_response = gpt_call(judgement_prompt)
|
67 |
|
68 |
return bot_response
|
|
|
2 |
from langchain.prompts import PromptTemplate
|
3 |
|
4 |
def debate_judgement(
|
|
|
5 |
user_debate_history,
|
6 |
bot_debate_history
|
7 |
):
|
8 |
+
|
9 |
+
if len(user_debate_history.split()) < 100:
|
10 |
+
bot_response = "Under the 100 words, evaluation is not possible."
|
11 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
judgement_prompt_preset = "\n".join([
|
13 |
"!!Instruction!",
|
14 |
"You are now the judge of this debate. Evaluate the debate according to the rules below.",
|
|
|
25 |
"Judgement: "
|
26 |
])
|
27 |
|
28 |
+
bot_response = gpt_call(judgement_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
return bot_response
|
bots/perfect_case_bot.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
def perfect_case_selector(debate_theme, topic):
|
5 |
+
|
6 |
+
if debate_theme == 'Education':
|
7 |
+
topic_list = [
|
8 |
+
"THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
|
9 |
+
"THS a world where the government gives cash that individuals can use to freely select their academic preference (including but not limited to school of choice, private academies, and tutoring) instead of funding for public education.",
|
10 |
+
"THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
|
11 |
+
]
|
12 |
+
elif debate_theme == 'Sports':
|
13 |
+
topic_list = [
|
14 |
+
"THBT having star players for team sports do more harm than good to the team.",
|
15 |
+
"THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
|
16 |
+
"THP a world where sports serves purely entertainment purposes even at the expense of fair play."
|
17 |
+
]
|
18 |
+
elif debate_theme == 'Religion':
|
19 |
+
topic_list = [
|
20 |
+
"THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
|
21 |
+
"Assuming feasibility, TH prefers a world where a panel of church leaders would create a universally accepted interpretation of the Bible that the believers would abide by.",
|
22 |
+
"THW aggressively crackdown on megachurches."
|
23 |
+
]
|
24 |
+
elif debate_theme == 'Justice':
|
25 |
+
topic_list = [
|
26 |
+
"In 2050, AI robots are able to replicate the appearance, conversation, and reaction to emotions of human beings. However, their intelligence still does not allow them to sense emotions and feelings such as pain, happiness, joy, and etc.",
|
27 |
+
"In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
|
28 |
+
"THP a world where the criminal justice system’s role is mainly for victim’s vengeance. THW allow prosecutors and victims to veto assigned judges."
|
29 |
+
]
|
30 |
+
elif debate_theme == 'Pandemic':
|
31 |
+
topic_list = [
|
32 |
+
"During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
|
33 |
+
"THW nullify the effect of medical patents in cases of medical emergencies.",
|
34 |
+
"THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
|
35 |
+
]
|
36 |
+
elif debate_theme == 'Politics':
|
37 |
+
topic_list = [
|
38 |
+
"Info: The Candle Light Will (촛불민심) is a term derived from the symbolic candle-light protests for the impeachment of the late president Park Geun Hye, commonly used to mean the people’s will to fight against corrupt governments. The Moon administration has frequently referred to the Candle Light Will as the driving force behind its election that grants legitimacy to its policies. THR the ‘candle light will’ narrative in the political discourse of South Korea.",
|
39 |
+
"THW impose a cap on the property and income of politicians.",
|
40 |
+
"THW give the youth extra votes."
|
41 |
+
]
|
42 |
+
elif debate_theme == 'Minority':
|
43 |
+
topic_list = [
|
44 |
+
"Context: A prominent member of the LGBT movement has discovered that a very influential politician helping the LGBT movement has been lying about their sexual orientation as being gay when they are straight. THW disclose this information.",
|
45 |
+
"THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
|
46 |
+
"THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
|
47 |
+
]
|
48 |
+
else:
|
49 |
+
topic_list = [
|
50 |
+
"THW remove all laws that relate to filial responsibilities.",
|
51 |
+
"THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
|
52 |
+
"Assuming it is possible to measure the ‘societal danger’ of the fetus in the future, THBT the state should raise infants that pose high levels of threat.",
|
53 |
+
"THBT any upper limits on prison sentences for particularly heinous crimes should be abolished.",
|
54 |
+
"THW require dating apps to anonymize profile pictures.",
|
55 |
+
"THW adopt a Pass/Fail grading system for students who suffer from mental health problems (e.g. depression, bipolar disorder, etc.).",
|
56 |
+
"THBT South Korean feminist movements should reject feminist icons that are adversarial and embody violence.",
|
57 |
+
"THBT freedom of speech should be considered obsolete.",
|
58 |
+
"THR the narrative that eccentric personalities are essential to create art.",
|
59 |
+
"THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
|
60 |
+
"THR the emphasis on longevity in relationships.",
|
61 |
+
"Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
|
62 |
+
]
|
63 |
+
|
64 |
+
perfect_case_result = "perfect_case_result"
|
65 |
+
|
66 |
+
return perfect_case_result
|