Spaces:
Runtime error
Runtime error
Merge remote-tracking branch 'upstream/master' into prototype_v0.1
Browse files- app.py +721 -162
- vocal_app.py +0 -631
- vocal_app.sh +0 -1
app.py
CHANGED
@@ -1,146 +1,277 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
2 |
from streamlit_chat import message
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# modules
|
5 |
-
from modules.
|
6 |
-
from modules.
|
7 |
-
|
|
|
8 |
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
#
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
dynamodb = get_db()
|
14 |
-
debate_bot_log_table = dynamodb.Table('debate_bot_log')
|
15 |
|
16 |
|
17 |
-
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
if 'generated' not in st.session_state:
|
24 |
-
st.session_state['generated'] = []
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
#############################################
|
33 |
|
34 |
-
if
|
35 |
st.session_state.user_id = ""
|
36 |
|
37 |
-
if
|
38 |
-
st.session_state.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
st.session_state.session_num = 0
|
42 |
|
43 |
-
if 'session_history_exist' not in st.session_state:
|
44 |
-
st.session_state.history_exist = False
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
|
|
49 |
|
50 |
-
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
56 |
else:
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
else:
|
62 |
-
st.session_state.session_num =
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
66 |
|
|
|
|
|
67 |
|
68 |
-
|
|
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
73 |
|
74 |
-
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
80 |
)
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
"THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
|
103 |
"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.",
|
104 |
"THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
|
105 |
-
|
106 |
-
elif debate_theme ==
|
107 |
-
topic_list =
|
108 |
"THBT having star players for team sports do more harm than good to the team.",
|
109 |
"THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
|
110 |
"THP a world where sports serves purely entertainment purposes even at the expense of fair play."
|
111 |
-
|
112 |
-
elif debate_theme ==
|
113 |
-
topic_list =
|
114 |
"THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
|
115 |
"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.",
|
116 |
"THW aggressively crackdown on megachurches."
|
117 |
-
|
118 |
-
elif debate_theme ==
|
119 |
-
topic_list =
|
120 |
"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.",
|
121 |
"In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
|
122 |
"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."
|
123 |
-
|
124 |
-
elif debate_theme ==
|
125 |
-
topic_list =
|
126 |
"During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
|
127 |
"THW nullify the effect of medical patents in cases of medical emergencies.",
|
128 |
"THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
|
129 |
-
|
130 |
-
elif debate_theme ==
|
131 |
-
topic_list =
|
132 |
"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.",
|
133 |
"THW impose a cap on the property and income of politicians.",
|
134 |
"THW give the youth extra votes."
|
135 |
-
|
136 |
-
elif debate_theme ==
|
137 |
-
topic_list =
|
138 |
"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.",
|
139 |
"THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
|
140 |
"THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
|
141 |
-
|
142 |
else:
|
143 |
-
topic_list =
|
144 |
"THW remove all laws that relate to filial responsibilities.",
|
145 |
"THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
|
146 |
"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.",
|
@@ -153,89 +284,517 @@ with st.form("first_form"):
|
|
153 |
"THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
|
154 |
"THR the emphasis on longevity in relationships.",
|
155 |
"Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
|
156 |
-
|
|
|
|
|
|
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
)
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
bot_role_list = (
|
167 |
-
"주제 정의",
|
168 |
-
"POI 연습",
|
169 |
-
"역할 추천",
|
170 |
-
"주장 비판",
|
171 |
-
"토론"
|
172 |
)
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
)
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
)
|
188 |
-
print("item", item)
|
189 |
|
190 |
-
|
191 |
-
if
|
192 |
-
|
193 |
-
|
194 |
else:
|
195 |
-
st.session_state.
|
196 |
-
st.session_state.
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
)
|
208 |
-
|
209 |
-
|
210 |
-
on_click=form_callback(st.session_state.history_exist)
|
211 |
)
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
st.session_state.past.append(user_input)
|
228 |
-
st.session_state.generated.append(output)
|
229 |
|
230 |
-
if st.session_state['generated']:
|
231 |
-
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
232 |
-
message(
|
233 |
-
st.session_state['past'][i],
|
234 |
-
is_user=True,
|
235 |
-
key=str(i) + '_user'
|
236 |
-
)
|
237 |
-
message(
|
238 |
-
st.session_state["generated"][i],
|
239 |
-
key=str(i),
|
240 |
-
#avatar_style="Fun Emoji"
|
241 |
-
)
|
|
|
1 |
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import openai
|
4 |
+
|
5 |
+
from gtts import gTTS
|
6 |
+
from collections import Counter
|
7 |
from streamlit_chat import message
|
8 |
|
9 |
+
# db_modules
|
10 |
+
from modules.db_modules import get_db, put_item, get_item, get_lastest_item
|
11 |
+
|
12 |
+
from dotenv import dotenv_values
|
13 |
+
from bots.judgement_bot import debate_judgement
|
14 |
+
from collections import Counter
|
15 |
+
import time
|
16 |
+
from time import strftime
|
17 |
+
from time import localtime
|
18 |
+
|
19 |
+
from audiorecorder import audiorecorder
|
20 |
+
|
21 |
# modules
|
22 |
+
from modules.gpt_modules import gpt_call, gpt_call_context
|
23 |
+
#from modules.whisper_modules import transcribe
|
24 |
+
|
25 |
+
config = dotenv_values(".env")
|
26 |
|
27 |
+
openai.organization = config.get('OPENAI_ORGANIZATION')
|
28 |
+
openai.api_key = config.get('OPENAI_API_KEY')
|
29 |
|
30 |
+
|
31 |
+
#openai.organization = st.secrets['OPENAI_ORGANIZATION']
|
32 |
+
#openai.api_key = st.secrets['OPENAI_API_KEY']
|
33 |
+
|
34 |
+
#########################################################
|
35 |
+
# GET DB
|
36 |
+
#########################################################
|
37 |
dynamodb = get_db()
|
|
|
38 |
|
39 |
|
40 |
+
#########################################################
|
41 |
+
# Time Stamp
|
42 |
+
#########################################################
|
43 |
+
tm = time.localtime()
|
44 |
+
time_stamp = strftime('%Y-%m-%d %I:%M:%S %p', tm)
|
45 |
|
|
|
|
|
46 |
|
47 |
+
#########################################################
|
48 |
+
# Page Configurations
|
49 |
+
#########################################################
|
50 |
+
st.set_page_config(page_title="Streamlit App")
|
51 |
|
52 |
+
#########################################################
|
53 |
+
# Initialize session state variables
|
54 |
+
#########################################################
|
55 |
+
if "page" not in st.session_state:
|
56 |
+
st.session_state.page = "Page 1"
|
57 |
|
58 |
+
if "topic" not in st.session_state:
|
59 |
+
st.session_state.topic = "None"
|
|
|
60 |
|
61 |
+
if "user_id" not in st.session_state:
|
62 |
st.session_state.user_id = ""
|
63 |
|
64 |
+
if "case1" not in st.session_state:
|
65 |
+
st.session_state.case1 = ""
|
66 |
+
|
67 |
+
if "case2" not in st.session_state:
|
68 |
+
st.session_state.case2 = ""
|
69 |
+
|
70 |
+
if "case3" not in st.session_state:
|
71 |
+
st.session_state.case3 = ""
|
72 |
+
|
73 |
+
if "page2_tab" not in st.session_state:
|
74 |
+
st.session_state.page2_tab = "tab1"
|
75 |
+
|
76 |
+
if "total_debate_history" not in st.session_state:
|
77 |
+
st.session_state.total_debate_history = []
|
78 |
+
|
79 |
+
if "user_debate_history" not in st.session_state:
|
80 |
+
st.session_state.user_debate_history = []
|
81 |
+
|
82 |
+
if "bot_debate_history" not in st.session_state:
|
83 |
+
st.session_state.bot_debate_history = []
|
84 |
+
|
85 |
+
if "user_debate_time" not in st.session_state:
|
86 |
+
st.session_state.user_debate_time = ""
|
87 |
+
|
88 |
+
if "pros_and_cons" not in st.session_state:
|
89 |
+
st.session_state.pros_and_cons = ""
|
90 |
+
|
91 |
+
if "start_time" not in st.session_state:
|
92 |
+
st.session_state.start_time = time.time()
|
93 |
+
|
94 |
+
if "end_time" not in st.session_state:
|
95 |
+
st.session_state.end_time = time.time()
|
96 |
|
97 |
+
if "debate_time" not in st.session_state:
|
98 |
+
st.session_state.debate_time = 0
|
99 |
+
|
100 |
+
if "pre_audio" not in st.session_state:
|
101 |
+
st.session_state.pre_audio = np.array([])
|
102 |
+
|
103 |
+
if "case1" not in st.session_state:
|
104 |
+
st.session_state.case1 = ""
|
105 |
+
|
106 |
+
if "case2" not in st.session_state:
|
107 |
+
st.session_state.case2 = ""
|
108 |
+
|
109 |
+
if "case3" not in st.session_state:
|
110 |
+
st.session_state.case3 = ""
|
111 |
+
|
112 |
+
|
113 |
+
# for db session number
|
114 |
+
if "session_num" not in st.session_state:
|
115 |
st.session_state.session_num = 0
|
116 |
|
|
|
|
|
117 |
|
118 |
+
#########################################################
|
119 |
+
# Save function (placeholder)
|
120 |
+
#########################################################
|
121 |
+
def save_info(user_id):
|
122 |
+
# You can add the code to save the submitted info (e.g., to a database)
|
123 |
+
st.session_state.user_id = user_id
|
124 |
|
125 |
+
print("User ID:", user_id)
|
126 |
|
127 |
+
# Session state
|
128 |
+
#session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
|
129 |
+
def write_info():
|
130 |
+
st.write('You choose', st.session_state.topic_list)
|
131 |
|
132 |
+
# for callback when button is clicked
|
133 |
+
def page_1_2_controller():
|
134 |
+
if st.session_state.user_id.strip() == "":
|
135 |
+
st.session_state.page = "Page 1"
|
136 |
+
st.warning('Please fill in all the required fields.')
|
137 |
else:
|
138 |
+
st.session_state.page = "Page 2"
|
139 |
+
print("save info")
|
140 |
+
|
141 |
+
save_info(
|
142 |
+
st.session_state.user_id
|
143 |
+
)
|
144 |
+
st.write('Information submitted successfully.')
|
145 |
+
|
146 |
+
#########################################################
|
147 |
+
# Session Update
|
148 |
+
#########################################################
|
149 |
+
debate_setting = get_lastest_item(
|
150 |
+
table=dynamodb.Table('DEBO_debate_setting'),
|
151 |
+
name_of_partition_key="user_id",
|
152 |
+
value_of_partition_key=st.session_state.user_id,
|
153 |
+
limit_num=1
|
154 |
+
)
|
155 |
+
# Session이 없다면, 0으로 초기화
|
156 |
+
if debate_setting == []:
|
157 |
+
st.session_state.session_num = 0
|
158 |
+
# User의 이전 기록에서 Session이 있다면, Session Number를 가져오고 갱신함
|
159 |
else:
|
160 |
+
st.session_state.session_num = debate_setting[0]['session_num']
|
161 |
+
|
162 |
+
def page_2_3_controller():
|
163 |
+
st.session_state.page = "Page 3"
|
164 |
+
|
165 |
+
def page2_tab_controller():
|
166 |
+
st.session_state.page2_tab = "tab2"
|
167 |
+
|
168 |
+
def page_3_4_controller():
|
169 |
+
st.session_state.page = "Page 4"
|
170 |
|
171 |
+
def page_4_5_controller():
|
172 |
+
st.session_state.page = "Page 5"
|
173 |
|
174 |
+
def page_5_6_controller():
|
175 |
+
st.session_state.page = "Page 6"
|
176 |
|
177 |
+
def page_2_6_controller():
|
178 |
+
st.session_state.page = "Page 6"
|
179 |
|
180 |
+
#########################################################
|
181 |
+
# Page 1
|
182 |
+
#########################################################
|
183 |
+
def page1():
|
184 |
|
185 |
+
# for local variables
|
186 |
+
topic_list = []
|
187 |
|
188 |
+
st.header('User Info & Debate Setting')
|
189 |
+
st.session_state.user_id = st.text_input(
|
190 |
+
label="Enter user ID",
|
191 |
+
max_chars=100,
|
192 |
+
placeholder="Enter user ID"
|
193 |
)
|
194 |
+
|
195 |
+
st.button(
|
196 |
+
label='Submit all information',
|
197 |
+
on_click=page_1_2_controller
|
198 |
+
)
|
199 |
+
# You can add a function here to save the submitted info
|
200 |
+
|
201 |
+
#########################################################
|
202 |
+
# Page 2
|
203 |
+
#########################################################
|
204 |
+
def page2():
|
205 |
+
st.header("Choose Option")
|
206 |
+
option_result = st.selectbox("Choose your option", ["Total Debate", "Evaluation Only & Analyzing Utterances"])
|
207 |
+
|
208 |
+
# add controller
|
209 |
+
if option_result == "Total Debate":
|
210 |
+
page_control_func = page_2_3_controller
|
211 |
+
elif option_result == "Evaluation Only & Analyzing Utterances":
|
212 |
+
page_control_func = page_2_6_controller
|
213 |
+
|
214 |
+
if st.button(
|
215 |
+
label='Submit all information',
|
216 |
+
on_click=page_control_func
|
217 |
+
):
|
218 |
+
st.write('Information submitted successfully.')
|
219 |
+
|
220 |
+
|
221 |
+
def page3():
|
222 |
+
#########################################################
|
223 |
+
# Tab 1 - Total Debate (토론 준비 -> 연습 -> 평가)
|
224 |
+
#########################################################
|
225 |
+
st.header("Total Debate")
|
226 |
+
debate_themes = ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc']
|
227 |
+
|
228 |
+
st.write("1. Select a debate theme")
|
229 |
+
st.session_state.debate_theme = st.selectbox("Choose your debate theme", debate_themes)
|
230 |
+
|
231 |
+
if st.session_state.debate_theme == 'Education':
|
232 |
+
topic_list = [
|
233 |
"THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
|
234 |
"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.",
|
235 |
"THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
|
236 |
+
]
|
237 |
+
elif st.session_state.debate_theme == 'Sports':
|
238 |
+
topic_list = [
|
239 |
"THBT having star players for team sports do more harm than good to the team.",
|
240 |
"THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
|
241 |
"THP a world where sports serves purely entertainment purposes even at the expense of fair play."
|
242 |
+
]
|
243 |
+
elif st.session_state.debate_theme == 'Religion':
|
244 |
+
topic_list = [
|
245 |
"THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
|
246 |
"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.",
|
247 |
"THW aggressively crackdown on megachurches."
|
248 |
+
]
|
249 |
+
elif st.session_state.debate_theme == 'Justice':
|
250 |
+
topic_list = [
|
251 |
"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.",
|
252 |
"In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
|
253 |
"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."
|
254 |
+
]
|
255 |
+
elif st.session_state.debate_theme == 'Pandemic':
|
256 |
+
topic_list = [
|
257 |
"During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
|
258 |
"THW nullify the effect of medical patents in cases of medical emergencies.",
|
259 |
"THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
|
260 |
+
]
|
261 |
+
elif st.session_state.debate_theme == 'Politics':
|
262 |
+
topic_list = [
|
263 |
"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.",
|
264 |
"THW impose a cap on the property and income of politicians.",
|
265 |
"THW give the youth extra votes."
|
266 |
+
]
|
267 |
+
elif st.session_state.debate_theme == 'Minority':
|
268 |
+
topic_list = [
|
269 |
"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.",
|
270 |
"THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
|
271 |
"THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
|
272 |
+
]
|
273 |
else:
|
274 |
+
topic_list = [
|
275 |
"THW remove all laws that relate to filial responsibilities.",
|
276 |
"THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
|
277 |
"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.",
|
|
|
284 |
"THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
|
285 |
"THR the emphasis on longevity in relationships.",
|
286 |
"Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
|
287 |
+
]
|
288 |
+
|
289 |
+
st.write("2. Select a topic")
|
290 |
+
st.session_state.topic = st.selectbox("Choose your topic", topic_list)
|
291 |
|
292 |
+
st.write("3. Write 3 cases")
|
293 |
+
|
294 |
+
#########################################################
|
295 |
+
# Case도 세션에 저장
|
296 |
+
#########################################################
|
297 |
+
st.session_state.case1 = st.text_area(
|
298 |
+
label="Case 1",
|
299 |
+
placeholder="Each case should be consisted of opinion, reasoning, and example.",
|
300 |
+
height=100
|
301 |
)
|
302 |
+
st.session_state.case2 = st.text_area(
|
303 |
+
label="Case 2",
|
304 |
+
placeholder="Each case should be consisted of opinion, reasoning, and example.",
|
305 |
+
height=100
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
)
|
307 |
+
st.session_state.case3 = st.text_area(
|
308 |
+
label="Case 3",
|
309 |
+
placeholder="Each case should be consisted of opinion, reasoning, and example.",
|
310 |
+
height=100
|
311 |
)
|
312 |
+
case_error_message = st.empty()
|
313 |
+
st.session_state.pros_and_cons = st.selectbox("Choose your Side (Pros and Cons)", ["Pros", "Cons"])
|
314 |
+
|
315 |
+
# Save the data to database
|
316 |
+
start = st.button(
|
317 |
+
label="Start Debate",
|
318 |
+
on_click=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 |
|
333 |
+
def validate_case(error_message):
|
334 |
+
if not st.session_state.case1 or not st.session_state.case2 or not st.session_state.case3:
|
335 |
+
case_error_message.error("Please fill out above all", icon="🚨")
|
336 |
+
return False
|
337 |
else:
|
338 |
+
# st.session_state.case1 = st.session_statecase1
|
339 |
+
# st.session_state.case2 = st.session_statecase2
|
340 |
+
# st.session_state.case3 = st.session_statecase3
|
341 |
+
return True
|
342 |
+
|
343 |
+
if start:
|
344 |
+
if validate_case(case_error_message):
|
345 |
+
page_3_4_controller()
|
346 |
+
st.experimental_rerun()
|
347 |
+
|
348 |
+
#########################################################
|
349 |
+
# Ask to GPT
|
350 |
+
#########################################################
|
351 |
+
with st.sidebar:
|
352 |
+
st.sidebar.title('Ask to GPT')
|
353 |
+
user_input = st.sidebar.text_area(
|
354 |
+
label="Question",
|
355 |
+
placeholder="Input text here",
|
356 |
+
height=100)
|
357 |
+
output = st.sidebar.button("Ask")
|
358 |
+
input_error_message = st.empty()
|
359 |
+
if output:
|
360 |
+
if not user_input:
|
361 |
+
input_error_message.error("Please enter your question")
|
362 |
+
result = ""
|
363 |
+
else:
|
364 |
+
result = gpt_call(user_input)
|
365 |
+
|
366 |
+
# save user_prompt and bot_response to database
|
367 |
+
put_item(
|
368 |
+
table=dynamodb.Table('DEBO_gpt_ask'),
|
369 |
+
item={
|
370 |
+
'user_id': st.session_state.user_id,
|
371 |
+
'time_stamp': time_stamp,
|
372 |
+
'user_prompt': user_input,
|
373 |
+
'bot_response': result,
|
374 |
+
'session_num': st.session_state.session_num,
|
375 |
+
}
|
376 |
+
)
|
377 |
+
|
378 |
+
else:
|
379 |
+
result = ""
|
380 |
+
|
381 |
+
st.sidebar.text_area(
|
382 |
+
label="Answer",
|
383 |
+
placeholder="(Answer will be shown here)",
|
384 |
+
value=result,
|
385 |
+
height=150)
|
386 |
+
|
387 |
+
#########################################################
|
388 |
+
# Page4
|
389 |
+
#########################################################
|
390 |
+
|
391 |
+
# generate response
|
392 |
+
def generate_response(prompt):
|
393 |
+
st.session_state['user_debate_history'].append(prompt)
|
394 |
+
st.session_state['total_debate_history'].append({"role": "user", "content": prompt})
|
395 |
+
response = gpt_call_context(st.session_state['total_debate_history'])
|
396 |
+
st.session_state['bot_debate_history'].append(response)
|
397 |
+
st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
|
398 |
+
return response
|
399 |
+
|
400 |
+
def execute_stt(audio):
|
401 |
+
wav_file = open("audio/audio.wav", "wb")
|
402 |
+
wav_file.write(audio.tobytes())
|
403 |
+
wav_file.close()
|
404 |
+
|
405 |
+
audio_file= open("audio/audio.wav", "rb")
|
406 |
+
user_input = openai.Audio.transcribe("whisper-1", audio_file).text
|
407 |
+
audio_file.close()
|
408 |
+
return user_input
|
409 |
+
|
410 |
+
def page4():
|
411 |
+
|
412 |
+
# time
|
413 |
+
st.session_state.start_time = time.time()
|
414 |
+
|
415 |
+
with st.sidebar:
|
416 |
+
st.sidebar.title('Ask to GPT')
|
417 |
+
user_input = st.sidebar.text_area(
|
418 |
+
label="Question",
|
419 |
+
placeholder="Input text here",
|
420 |
+
height=100)
|
421 |
+
output = st.sidebar.button("Ask")
|
422 |
+
input_error_message = st.empty()
|
423 |
+
if output:
|
424 |
+
if not user_input:
|
425 |
+
input_error_message.error("Please enter your question")
|
426 |
+
result = ""
|
427 |
+
else:
|
428 |
+
result = gpt_call(user_input)
|
429 |
+
put_item(
|
430 |
+
table=dynamodb.Table('DEBO_gpt_ask'),
|
431 |
+
item={
|
432 |
+
'user_id': st.session_state.user_id,
|
433 |
+
'time_stamp': time_stamp,
|
434 |
+
'user_prompt': user_input,
|
435 |
+
'bot_response': result,
|
436 |
+
'session_num': st.session_state.session_num,
|
437 |
+
}
|
438 |
+
)
|
439 |
+
else:
|
440 |
+
result = ""
|
441 |
+
|
442 |
+
st.sidebar.text_area(
|
443 |
+
label="Answer",
|
444 |
+
placeholder="(Answer will be shown here)",
|
445 |
+
value=result,
|
446 |
+
height=150)
|
447 |
+
|
448 |
+
# default system prompt settings
|
449 |
+
if not st.session_state['total_debate_history']:
|
450 |
+
debate_preset = "\n".join([
|
451 |
+
"Debate Rules: ",
|
452 |
+
"1) This debate will be divided into two teams, pro and con, with two debates on each team.",
|
453 |
+
"2) The order of speaking is: first debater for the pro side, first debater for the con side, second debater for the pro side, second debater for the con side.",
|
454 |
+
"3) Answer logically with an introduction, body, and conclusion.", #add this one.
|
455 |
+
"4) Your role : " + st.session_state["pros_and_cons"] + " side debator",
|
456 |
+
"5) Debate subject: " + st.session_state['topic'],
|
457 |
+
])
|
458 |
+
first_prompt = "Now we're going to start. Summarize the subject and your role. And ask user ready to begin."
|
459 |
+
|
460 |
+
st.session_state['total_debate_history'] = [
|
461 |
+
{"role": "system", "content": debate_preset}
|
462 |
+
]
|
463 |
+
response = gpt_call(debate_preset + "\n" + first_prompt, role="system")
|
464 |
+
st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
|
465 |
+
st.session_state['bot_debate_history'].append(response)
|
466 |
+
|
467 |
+
# 아래에서 한번에 저장
|
468 |
+
|
469 |
+
# put_item(
|
470 |
+
# table=dynamodb.Table('DEBO_debate_main'),
|
471 |
+
# item={
|
472 |
+
# 'user_id': st.session_state.user_id,
|
473 |
+
# 'time_stamp': time_stamp,
|
474 |
+
# 'session_num': st.session_state.session_num,
|
475 |
+
# 'bot_response': response,
|
476 |
+
# 'user_prompt': "",
|
477 |
+
# 'turn_num': 0,
|
478 |
+
# }
|
479 |
+
# )
|
480 |
+
|
481 |
+
|
482 |
+
# container for chat history
|
483 |
+
response_container = st.container()
|
484 |
+
# container for text box
|
485 |
+
container = st.container()
|
486 |
+
|
487 |
+
with container:
|
488 |
+
with st.form(key='my_form', clear_on_submit=True):
|
489 |
+
user_input = None
|
490 |
+
# record voice
|
491 |
+
audio = audiorecorder("Click to record", "Recording...")
|
492 |
+
if np.array_equal(st.session_state['pre_audio'], audio):
|
493 |
+
audio = np.array([])
|
494 |
+
print("audio", audio)
|
495 |
+
|
496 |
+
#user_input = st.text_area("You:", key='input', height=100)
|
497 |
+
submit_buttom = st.form_submit_button(label='Send')
|
498 |
+
send_error_message = st.empty()
|
499 |
+
|
500 |
+
#if submit_buttom and user_input:
|
501 |
+
if submit_buttom:
|
502 |
+
if audio.any():
|
503 |
+
user_input = execute_stt(audio)
|
504 |
+
response = generate_response(user_input)
|
505 |
+
st.session_state['pre_audio'] = audio
|
506 |
+
|
507 |
+
debate_main_latest_data = get_lastest_item(
|
508 |
+
table=dynamodb.Table('DEBO_debate_main'),
|
509 |
+
name_of_partition_key="user_id",
|
510 |
+
value_of_partition_key=st.session_state.user_id,
|
511 |
+
limit_num=1
|
512 |
+
)
|
513 |
+
|
514 |
+
if debate_main_latest_data == []:
|
515 |
+
turn_num = 0
|
516 |
+
else:
|
517 |
+
turn_num = debate_main_latest_data[0]['turn_num']
|
518 |
+
|
519 |
+
put_item(
|
520 |
+
table=dynamodb.Table('DEBO_debate_main'),
|
521 |
+
item={
|
522 |
+
'user_id': st.session_state.user_id,
|
523 |
+
'time_stamp': time_stamp,
|
524 |
+
'session_num': st.session_state.session_num,
|
525 |
+
'bot_response': response,
|
526 |
+
'user_prompt': user_input,
|
527 |
+
'turn_num': turn_num,
|
528 |
+
}
|
529 |
+
)
|
530 |
+
|
531 |
+
else:
|
532 |
+
send_error_message.error("Please record your voice first", icon="🚨")
|
533 |
+
print("Nothing to transcribe")
|
534 |
+
|
535 |
+
#TODO 사용자 input이 없을 때도 reloading으로 buffering 걸리는 문제 해결
|
536 |
+
with response_container:
|
537 |
+
message(st.session_state['bot_debate_history'][0], key='0_bot')
|
538 |
+
text_to_speech = gTTS(text=st.session_state['bot_debate_history'][0], lang='en', slow=False)
|
539 |
+
text_to_speech.save(f'audio/test_gtts_0.mp3')
|
540 |
+
audio_file = open(f'audio/test_gtts_0.mp3', 'rb')
|
541 |
+
audio_bytes = audio_file.read()
|
542 |
+
st.audio(audio_bytes, format='audio/ogg')
|
543 |
+
|
544 |
+
for i in range(len(st.session_state['user_debate_history'])):
|
545 |
+
message(st.session_state['user_debate_history'][i], is_user=True, key=str(i)+'_user')
|
546 |
+
message(st.session_state['bot_debate_history'][i + 1], key=str(i + 1)+'_bot')
|
547 |
+
text_to_speech = gTTS(text=st.session_state['bot_debate_history'][i + 1], lang='en', slow=False)
|
548 |
+
text_to_speech.save(f'audio/test_gtts_{str(i + 1)}.mp3')
|
549 |
+
audio_file = open(f'audio/test_gtts_{str(i + 1)}.mp3', 'rb')
|
550 |
+
audio_bytes = audio_file.read()
|
551 |
+
st.audio(audio_bytes, format='audio/ogg')
|
552 |
+
|
553 |
+
if st.button(label="Next",
|
554 |
+
on_click=page_4_5_controller):
|
555 |
+
st.write('Information submitted successfully.')
|
556 |
+
|
557 |
+
print("#"*50)
|
558 |
+
print(st.session_state)
|
559 |
+
print("#"*50)
|
560 |
+
|
561 |
+
#########################################################
|
562 |
+
# Page5 - Total Debate Evaluation
|
563 |
+
#########################################################
|
564 |
+
def page5():
|
565 |
+
|
566 |
+
# end time
|
567 |
+
st.session_state.end_time = time.time()
|
568 |
+
st.session_state.debate_time = st.session_state.end_time - st.session_state.start_time
|
569 |
+
|
570 |
+
# st.tab
|
571 |
+
st.header('Total Debate Evaluation')
|
572 |
+
|
573 |
+
tab1, tab2 = st.tabs(['Debate Judgement', 'Debate Analysis'])
|
574 |
+
|
575 |
+
with tab1:
|
576 |
+
st.header("Debate Evaluation")
|
577 |
+
|
578 |
+
debate_themes = ['User-Bot', "User", "Bot"]
|
579 |
+
|
580 |
+
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
581 |
+
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
582 |
+
|
583 |
+
with st.spinner('Wait for judgement result...'):
|
584 |
+
judgement_result = ""
|
585 |
+
|
586 |
+
user_debate_history = "".join(
|
587 |
+
st.session_state.user_debate_history
|
588 |
+
)
|
589 |
+
bot_debate_history = "".join(
|
590 |
+
st.session_state.bot_debate_history
|
591 |
+
)
|
592 |
+
|
593 |
+
judgement_result = debate_judgement(
|
594 |
+
judgement_who,
|
595 |
+
user_debate_history,
|
596 |
+
bot_debate_history
|
597 |
+
)
|
598 |
+
|
599 |
+
st.write("Debate Judgement Result")
|
600 |
+
st.write(judgement_result)
|
601 |
+
|
602 |
+
if judgement_result != "":
|
603 |
+
put_item(
|
604 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
605 |
+
item={
|
606 |
+
'user_id': st.session_state.user_id,
|
607 |
+
'time_stamp': time_stamp,
|
608 |
+
'judgement_text': judgement_result,
|
609 |
+
'session_num': st.session_state.session_num,
|
610 |
+
}
|
611 |
+
)
|
612 |
+
|
613 |
+
st.success('Done!')
|
614 |
+
|
615 |
+
with tab2:
|
616 |
+
st.header('Debate Analysis')
|
617 |
+
|
618 |
+
# 유저의 history를 기반으로 발화량, 빈출 단어, 발화 습관 세 가지를 분석
|
619 |
+
user_history = st.session_state.user_debate_history
|
620 |
+
|
621 |
+
# 1. 발화량: 총 단어, 평균 속도(단어/시간)를 평균 발화량 혹은 참고 지표와 비교해 제시
|
622 |
+
|
623 |
+
# 총 단어
|
624 |
+
# 텍스트를 단어로 분할합니다.
|
625 |
+
# 각 단어의 빈도를 계산합니다.
|
626 |
+
total_word_count = len(user_history)
|
627 |
+
#total_word_count = len(user_history.split())
|
628 |
+
st.write("Total Word Count: ", total_word_count)
|
629 |
+
|
630 |
+
# 평균 속도(단어/시간)
|
631 |
+
#user_debate_time = st.session_state.user_debate_time
|
632 |
+
average_word_per_time = total_word_count / st.session_state.debate_time # 시간 단위보고 나중에 수정하기
|
633 |
+
st.write("Average Word Per Time: ", average_word_per_time)
|
634 |
+
|
635 |
+
# 2. 빈출 단어: 반복해서 사용하는 단어 리스트
|
636 |
+
# 빈도 계산
|
637 |
+
frequency = Counter(user_history)
|
638 |
+
# 가장 빈도가 높은 데이터 출력
|
639 |
+
most_common_data = frequency.most_common(10)
|
640 |
+
print(most_common_data)
|
641 |
+
st.write("Most Common Words: ", most_common_data)
|
642 |
+
|
643 |
+
# 3. 발화 습관: 불필요한 언어습관(아, 음)
|
644 |
+
# whisper preprocesser에서 주면
|
645 |
+
disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
|
646 |
+
# Count the disfluency words
|
647 |
+
disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
648 |
+
st.write("Disfluency Counts: ", disfluency_counts)
|
649 |
+
|
650 |
+
if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
|
651 |
+
put_item(
|
652 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
653 |
+
item={
|
654 |
+
'user_id': st.session_state.user_id,
|
655 |
+
'time_stamp': time_stamp,
|
656 |
+
'total_word_count': total_word_count,
|
657 |
+
'average_word_per_time': average_word_per_time,
|
658 |
+
'disfluency_counts': disfluency_counts,
|
659 |
+
'session_num': st.session_state.session_num,
|
660 |
+
}
|
661 |
+
)
|
662 |
+
|
663 |
+
# 유저와 봇의 대화 데이터가 세션에 남아있음
|
664 |
+
# st.session_state.debate_history
|
665 |
|
666 |
+
|
667 |
+
#########################################################
|
668 |
+
# Page6
|
669 |
+
#########################################################
|
670 |
+
|
671 |
+
def page6():
|
672 |
+
|
673 |
+
# end time
|
674 |
+
st.session_state.end_time = time.time()
|
675 |
+
st.session_state.debate_time = st.session_state.end_time - st.session_state.start_time
|
676 |
+
|
677 |
+
# st.tab
|
678 |
+
st.header('Total Debate Evaluation')
|
679 |
+
|
680 |
+
tab1, tab2 = st.tabs(['Debate Judgement', 'Debate Analysis'])
|
681 |
+
|
682 |
+
with tab1:
|
683 |
+
st.header("Debate Evaluation")
|
684 |
+
|
685 |
+
debate_themes = ['User-Bot', "User", "Bot"]
|
686 |
+
|
687 |
+
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
688 |
+
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
689 |
+
|
690 |
+
judgement_result = ""
|
691 |
+
if judgement_result == "":
|
692 |
+
st.write("Wait for judgement result...")
|
693 |
+
|
694 |
+
user_debate_history = "".join(
|
695 |
+
st.session_state.user_debate_history
|
696 |
)
|
697 |
+
bot_debate_history = "".join(
|
698 |
+
st.session_state.bot_debate_history
|
|
|
699 |
)
|
700 |
|
701 |
+
judgement_result = debate_judgement(
|
702 |
+
judgement_who,
|
703 |
+
user_debate_history,
|
704 |
+
bot_debate_history
|
705 |
+
)
|
706 |
+
|
707 |
+
if judgement_result != "":
|
708 |
+
put_item(
|
709 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
710 |
+
item={
|
711 |
+
'user_id': st.session_state.user_id,
|
712 |
+
'time_stamp': time_stamp,
|
713 |
+
'judgement_text': judgement_result,
|
714 |
+
'session_num': st.session_state.session_num,
|
715 |
+
}
|
716 |
+
)
|
717 |
+
|
718 |
+
st.write("Debate Judgement Result")
|
719 |
+
st.write(judgement_result)
|
720 |
+
|
721 |
+
with tab2:
|
722 |
+
st.header('Debate Analysis')
|
723 |
+
|
724 |
+
# 유저의 history를 기반으로 발화량, 빈출 단어, 발화 습관 세 가지를 분석
|
725 |
+
user_history = st.session_state.user_debate_history
|
726 |
+
|
727 |
+
# 1. 발화량: 총 단어, 평균 속도(단어/시간)를 평균 발화량 혹은 참고 지표와 비교해 제시
|
728 |
+
|
729 |
+
# 총 단어
|
730 |
+
# 텍스트를 단어로 분할합니다.
|
731 |
+
# 각 단어의 빈도를 계산합니다.
|
732 |
+
total_word_count = len(user_history)
|
733 |
+
#total_word_count = len(user_history.split())
|
734 |
+
st.write("Total Word Count: ", total_word_count)
|
735 |
+
|
736 |
+
# 평균 속도(단어/시간)
|
737 |
+
#user_debate_time = st.session_state.user_debate_time
|
738 |
+
average_word_per_time = total_word_count / st.session_state.debate_time # 시간 단위보고 나중에 수정하기
|
739 |
+
st.write("Average Word Per Time: ", average_word_per_time)
|
740 |
+
|
741 |
+
# 2. 빈출 단어: 반복해서 사용하는 단어 리스트
|
742 |
+
# 빈도 계산
|
743 |
+
frequency = Counter(user_history)
|
744 |
+
# 가장 빈도가 높은 데이터 출력
|
745 |
+
most_common_data = frequency.most_common(10)
|
746 |
+
print(most_common_data)
|
747 |
+
st.write("Most Common Words: ", most_common_data)
|
748 |
+
|
749 |
+
# 3. 발화 습관: 불필요한 언어습관(아, 음)
|
750 |
+
# whisper preprocesser에서 주면
|
751 |
+
disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
|
752 |
+
# Count the disfluency words
|
753 |
+
disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
754 |
+
st.write("Disfluency Counts: ", disfluency_counts)
|
755 |
+
|
756 |
+
if total_word_count != "" and average_word_per_time != "" and disfluency_counts != "":
|
757 |
+
put_item(
|
758 |
+
table=dynamodb.Table('DEBO_evaluation'),
|
759 |
+
item={
|
760 |
+
'user_id': st.session_state.user_id,
|
761 |
+
'time_stamp': time_stamp,
|
762 |
+
'total_word_count': total_word_count,
|
763 |
+
'average_word_per_time': average_word_per_time,
|
764 |
+
'disfluency_counts': disfluency_counts,
|
765 |
+
'session_num': st.session_state.session_num,
|
766 |
+
}
|
767 |
+
)
|
768 |
+
|
769 |
+
# 유저와 봇의 대화 데이터가 세션에 남아있음
|
770 |
+
# st.session_state.debate_history
|
771 |
+
|
772 |
+
############################################
|
773 |
+
# Visualization
|
774 |
+
############################################
|
775 |
+
|
776 |
+
# 이전에 기록된 값이 있다면, 그래프를 그립니다.
|
777 |
+
# 이전에 기록된 값이 없다면, 그래프를 그리지 않습니다.
|
778 |
+
|
779 |
+
|
780 |
+
|
781 |
+
#########################################################
|
782 |
+
# Page Routing
|
783 |
+
#########################################################
|
784 |
+
pages = {
|
785 |
+
"Page 1": page1, # user_id와 openai_key를 입력받는 페이지
|
786 |
+
"Page 2": page2, # 원하는 기능을 선택하는 페이지
|
787 |
+
"Page 3": page3, # Total Debate
|
788 |
+
"Page 4": page4, # Evaluation Only
|
789 |
+
"Page 5": page5, # Analyzing Utterances
|
790 |
+
"Page 6": page6,
|
791 |
+
}
|
792 |
+
|
793 |
+
selection = st.session_state.page
|
794 |
+
print("selection:", selection)
|
795 |
+
|
796 |
+
page = pages[selection]
|
797 |
+
# Execute selected page function
|
798 |
+
page()
|
799 |
|
|
|
|
|
800 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vocal_app.py
DELETED
@@ -1,631 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import numpy as np
|
3 |
-
import openai
|
4 |
-
|
5 |
-
from gtts import gTTS
|
6 |
-
from collections import Counter
|
7 |
-
from streamlit_chat import message
|
8 |
-
|
9 |
-
from dotenv import dotenv_values
|
10 |
-
from bots.judgement_bot import debate_judgement
|
11 |
-
from collections import Counter
|
12 |
-
import time
|
13 |
-
|
14 |
-
from audiorecorder import audiorecorder
|
15 |
-
|
16 |
-
# modules
|
17 |
-
from modules.gpt_modules import gpt_call, gpt_call_context
|
18 |
-
#from modules.whisper_modules import transcribe
|
19 |
-
|
20 |
-
config = dotenv_values(".env")
|
21 |
-
|
22 |
-
openai.organization = config.get('OPENAI_ORGANIZATION')
|
23 |
-
openai.api_key = config.get('OPENAI_API_KEY')
|
24 |
-
|
25 |
-
|
26 |
-
# Page Configuration
|
27 |
-
st.set_page_config(page_title="Streamlit App")
|
28 |
-
|
29 |
-
# Initialize session state variables
|
30 |
-
if "page" not in st.session_state:
|
31 |
-
st.session_state.page = "Page 1"
|
32 |
-
|
33 |
-
if "topic" not in st.session_state:
|
34 |
-
st.session_state.topic = "None"
|
35 |
-
|
36 |
-
if "user_id" not in st.session_state:
|
37 |
-
st.session_state.user_id = ""
|
38 |
-
|
39 |
-
if "openAI_token" not in st.session_state:
|
40 |
-
st.session_state.openAI_token = ""
|
41 |
-
|
42 |
-
if "case1" not in st.session_state:
|
43 |
-
st.session_state.case1 = ""
|
44 |
-
|
45 |
-
if "case2" not in st.session_state:
|
46 |
-
st.session_state.case2 = ""
|
47 |
-
|
48 |
-
if "case3" not in st.session_state:
|
49 |
-
st.session_state.case3 = ""
|
50 |
-
|
51 |
-
if "page2_tab" not in st.session_state:
|
52 |
-
st.session_state.page2_tab = "tab1"
|
53 |
-
|
54 |
-
if "total_debate_history" not in st.session_state:
|
55 |
-
st.session_state.total_debate_history = []
|
56 |
-
|
57 |
-
if "user_debate_history" not in st.session_state:
|
58 |
-
st.session_state.user_debate_history = []
|
59 |
-
|
60 |
-
if "bot_debate_history" not in st.session_state:
|
61 |
-
st.session_state.bot_debate_history = []
|
62 |
-
|
63 |
-
if "user_debate_time" not in st.session_state:
|
64 |
-
st.session_state.user_debate_time = ""
|
65 |
-
|
66 |
-
if "pros_and_cons" not in st.session_state:
|
67 |
-
st.session_state.pros_and_cons = ""
|
68 |
-
|
69 |
-
# Time session
|
70 |
-
if "start_time" not in st.session_state:
|
71 |
-
st.session_state.start_time = time.time()
|
72 |
-
|
73 |
-
if "end_time" not in st.session_state:
|
74 |
-
st.session_state.end_time = time.time()
|
75 |
-
|
76 |
-
if "debate_time" not in st.session_state:
|
77 |
-
st.session_state.debate_time = 0
|
78 |
-
|
79 |
-
if "pre_audio" not in st.session_state:
|
80 |
-
st.session_state.pre_audio = np.array([])
|
81 |
-
|
82 |
-
|
83 |
-
# Save function (placeholder)
|
84 |
-
def save_info(user_id, openAI_token, debate_theme):
|
85 |
-
# You can add the code to save the submitted info (e.g., to a database)
|
86 |
-
st.session_state.user_id = user_id
|
87 |
-
st.session_state.openAI_token = openAI_token
|
88 |
-
st.session_state.debate_theme = debate_theme
|
89 |
-
|
90 |
-
print("User ID:", user_id)
|
91 |
-
print("OpenAI token:", openAI_token)
|
92 |
-
print("Debate theme:", debate_theme)
|
93 |
-
|
94 |
-
# Session state
|
95 |
-
#session_state = SessionState.get(user_id="", openAI_token="", debate_theme="")
|
96 |
-
|
97 |
-
def write_info():
|
98 |
-
st.write('You choose', st.session_state.topic_list)
|
99 |
-
|
100 |
-
# for callback when button is clicked
|
101 |
-
def page_1_2_controller():
|
102 |
-
if st.session_state.user_id.strip() == "" or st.session_state.openAI_token.strip() == "":
|
103 |
-
st.session_state.page = "Page 1"
|
104 |
-
st.warning('Please fill in all the required fields.')
|
105 |
-
else:
|
106 |
-
st.session_state.page = "Page 2"
|
107 |
-
|
108 |
-
def page_2_3_controller():
|
109 |
-
st.session_state.page = "Page 3"
|
110 |
-
|
111 |
-
def page2_tab_controller():
|
112 |
-
st.session_state.page2_tab = "tab2"
|
113 |
-
|
114 |
-
def page_3_4_controller():
|
115 |
-
st.session_state.page = "Page 4"
|
116 |
-
|
117 |
-
def page_4_5_controller():
|
118 |
-
st.session_state.page = "Page 5"
|
119 |
-
|
120 |
-
def page_5_6_controller():
|
121 |
-
st.session_state.page = "Page 6"
|
122 |
-
|
123 |
-
def page_2_6_controller():
|
124 |
-
st.session_state.page = "Page 6"
|
125 |
-
|
126 |
-
#########################################################
|
127 |
-
# Page 1
|
128 |
-
#########################################################
|
129 |
-
def page1():
|
130 |
-
|
131 |
-
# for local variables
|
132 |
-
topic_list = []
|
133 |
-
|
134 |
-
st.header('User Info & Debate Setting')
|
135 |
-
st.session_state.user_id = st.text_input(
|
136 |
-
label="Enter user ID",
|
137 |
-
max_chars=100,
|
138 |
-
placeholder="Enter user ID"
|
139 |
-
)
|
140 |
-
st.session_state.openAI_token = st.text_input(
|
141 |
-
label="Enter OpenAI token",
|
142 |
-
max_chars=200,
|
143 |
-
placeholder="Enter OpenAI token"
|
144 |
-
)
|
145 |
-
|
146 |
-
if st.button(
|
147 |
-
label='Submit all information',
|
148 |
-
on_click=page_1_2_controller
|
149 |
-
):
|
150 |
-
# You can add a function here to save the submitted info
|
151 |
-
if st.session_state.user_id != '' and st.session_state.openAI_token != '':
|
152 |
-
save_info(
|
153 |
-
st.session_state.user_id,
|
154 |
-
st.session_state.openAI_token,
|
155 |
-
st.session_state.debate_theme
|
156 |
-
)
|
157 |
-
st.write('Information submitted successfully.')
|
158 |
-
|
159 |
-
#########################################################
|
160 |
-
# Page 2
|
161 |
-
#########################################################
|
162 |
-
def page2():
|
163 |
-
st.header("Choose Option")
|
164 |
-
option_result = st.selectbox("Choose your option", ["Total Debate", "Evaluation Only & Analyzing Utterances"])
|
165 |
-
|
166 |
-
# add controller
|
167 |
-
if option_result == "Total Debate":
|
168 |
-
page_control_func = page_2_3_controller
|
169 |
-
elif option_result == "Evaluation Only & Analyzing Utterances":
|
170 |
-
page_control_func = page_2_6_controller
|
171 |
-
|
172 |
-
if st.button(
|
173 |
-
label='Submit all information',
|
174 |
-
on_click=page_control_func
|
175 |
-
):
|
176 |
-
st.write('Information submitted successfully.')
|
177 |
-
|
178 |
-
|
179 |
-
def page3():
|
180 |
-
#########################################################
|
181 |
-
# Tab 1 - Total Debate (토론 준비 -> 연습 -> 평가)
|
182 |
-
#########################################################
|
183 |
-
st.header("Total Debate")
|
184 |
-
debate_themes = ['Education','Sports','Religion','Justice','Pandemic','Politics','Minority','etc']
|
185 |
-
|
186 |
-
st.write("1. Select a debate theme")
|
187 |
-
st.session_state.debate_theme = st.selectbox("Choose your debate theme", debate_themes)
|
188 |
-
|
189 |
-
if st.session_state.debate_theme == 'Education':
|
190 |
-
topic_list = [
|
191 |
-
"THBT college entrance examinations should accept students only on the basis of their academic performance in secondary education.",
|
192 |
-
"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.",
|
193 |
-
"THW abolish all requirements and evaluation criteria in higher education (i.e., attendance, exams, assignments)."
|
194 |
-
]
|
195 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
196 |
-
elif st.session_state.debate_theme == 'Sports':
|
197 |
-
topic_list = [
|
198 |
-
"THBT having star players for team sports do more harm than good to the team.",
|
199 |
-
"THR the emphasis on winning a medal in the Olympics as a core symbol of success.",
|
200 |
-
"THP a world where sports serves purely entertainment purposes even at the expense of fair play."
|
201 |
-
]
|
202 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
203 |
-
elif st.session_state.debate_theme == 'Religion':
|
204 |
-
topic_list = [
|
205 |
-
"THW, as a religious group/leader, cease attempts at increasing the number of believers and instead prioritize boosting loyalty amongst adherents to the religion.",
|
206 |
-
"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.",
|
207 |
-
"THW aggressively crackdown on megachurches."
|
208 |
-
]
|
209 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
210 |
-
elif st.session_state.debate_theme == 'Justice':
|
211 |
-
topic_list = [
|
212 |
-
"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.",
|
213 |
-
"In the case a human destroys the robot beyond repair, THW charge murder instead of property damage.",
|
214 |
-
"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."
|
215 |
-
]
|
216 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
217 |
-
elif st.session_state.debate_theme == 'Pandemic':
|
218 |
-
topic_list = [
|
219 |
-
"During a pandemic, THBT businesses that benefit from the pandemic should be additionally taxed.",
|
220 |
-
"THW nullify the effect of medical patents in cases of medical emergencies.",
|
221 |
-
"THW ban media content that denies the efficacy of the COVID-19 without substantial evidence."
|
222 |
-
]
|
223 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
224 |
-
elif st.session_state.debate_theme == 'Politics':
|
225 |
-
topic_list = [
|
226 |
-
"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.",
|
227 |
-
"THW impose a cap on the property and income of politicians.",
|
228 |
-
"THW give the youth extra votes."
|
229 |
-
]
|
230 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
231 |
-
elif st.session_state.debate_theme == 'Minority':
|
232 |
-
topic_list = [
|
233 |
-
"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.",
|
234 |
-
"THBT the LGBTQIA+ movement should denounce the existence of marriage as opposed to fighting for equal marriage rights.",
|
235 |
-
"THBT the LGBTQIA+ movement should condemn the consumption of movies and TV shows that cast straight actors/actresses in non-heterosexual identified roles."
|
236 |
-
]
|
237 |
-
#topic = st.selectbox("Select a topic_list", topic_list)
|
238 |
-
else:
|
239 |
-
topic_list = [
|
240 |
-
"THW remove all laws that relate to filial responsibilities.",
|
241 |
-
"THW require parents to receive approval from experts in relevant fields before making crucial decisions for their children.",
|
242 |
-
"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.",
|
243 |
-
"THBT any upper limits on prison sentences for particularly heinous crimes should be abolished.",
|
244 |
-
"THW require dating apps to anonymize profile pictures.",
|
245 |
-
"THW adopt a Pass/Fail grading system for students who suffer from mental health problems (e.g. depression, bipolar disorder, etc.).",
|
246 |
-
"THBT South Korean feminist movements should reject feminist icons that are adversarial and embody violence.",
|
247 |
-
"THBT freedom of speech should be considered obsolete.",
|
248 |
-
"THR the narrative that eccentric personalities are essential to create art.",
|
249 |
-
"THW allow parents of severely mentally disabled children to medically impede their children's physical growth.",
|
250 |
-
"THR the emphasis on longevity in relationships.",
|
251 |
-
"Assuming feasibility, THW choose to continuously relive the happiest moment of one’s life."
|
252 |
-
]
|
253 |
-
|
254 |
-
st.write("2. Select a topic")
|
255 |
-
st.session_state.topic = st.selectbox("Choose your topic", topic_list)
|
256 |
-
|
257 |
-
st.write("3. Write 3 cases")
|
258 |
-
|
259 |
-
case1 = st.text_area(
|
260 |
-
label="Case 1",
|
261 |
-
placeholder="Each case should be consisted of opinion, reasoning, and example.",
|
262 |
-
height=100
|
263 |
-
)
|
264 |
-
case2 = st.text_area(
|
265 |
-
label="Case 2",
|
266 |
-
placeholder="Each case should be consisted of opinion, reasoning, and example.",
|
267 |
-
height=100
|
268 |
-
)
|
269 |
-
case3 = st.text_area(
|
270 |
-
label="Case 3",
|
271 |
-
placeholder="Each case should be consisted of opinion, reasoning, and example.",
|
272 |
-
height=100
|
273 |
-
)
|
274 |
-
case_error_message = st.empty()
|
275 |
-
st.session_state.pros_and_cons = st.selectbox("Choose your Side (Pros and Cons)", ["Pros", "Cons"])
|
276 |
-
|
277 |
-
start = st.button(label="Start Debate")
|
278 |
-
|
279 |
-
def validate_case(error_message):
|
280 |
-
if not case1 or not case2 or not case3:
|
281 |
-
case_error_message.error("Please fill out above all", icon="🚨")
|
282 |
-
return False
|
283 |
-
else:
|
284 |
-
st.session_state.case1 = case1
|
285 |
-
st.session_state.case2 = case2
|
286 |
-
st.session_state.case3 = case3
|
287 |
-
return True
|
288 |
-
|
289 |
-
if start:
|
290 |
-
if validate_case(case_error_message):
|
291 |
-
page_3_4_controller()
|
292 |
-
st.experimental_rerun()
|
293 |
-
|
294 |
-
with st.sidebar:
|
295 |
-
st.sidebar.title('Ask to GPT')
|
296 |
-
user_input = st.sidebar.text_area(
|
297 |
-
label="Question",
|
298 |
-
placeholder="Input text here",
|
299 |
-
height=100)
|
300 |
-
output = st.sidebar.button("Ask")
|
301 |
-
input_error_message = st.empty()
|
302 |
-
if output:
|
303 |
-
if not user_input:
|
304 |
-
input_error_message.error("Please enter your question")
|
305 |
-
result = ""
|
306 |
-
else:
|
307 |
-
result = gpt_call(user_input)
|
308 |
-
else:
|
309 |
-
result = ""
|
310 |
-
|
311 |
-
st.sidebar.text_area(
|
312 |
-
label="Answer",
|
313 |
-
placeholder="(Answer will be shown here)",
|
314 |
-
value=result,
|
315 |
-
height=150)
|
316 |
-
|
317 |
-
#########################################################
|
318 |
-
# Page4
|
319 |
-
#########################################################
|
320 |
-
|
321 |
-
# generate response
|
322 |
-
def generate_response(prompt):
|
323 |
-
st.session_state['user_debate_history'].append(prompt)
|
324 |
-
st.session_state['total_debate_history'].append({"role": "user", "content": prompt})
|
325 |
-
response = gpt_call_context(st.session_state['total_debate_history'])
|
326 |
-
st.session_state['bot_debate_history'].append(response)
|
327 |
-
st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
|
328 |
-
return response
|
329 |
-
|
330 |
-
def execute_stt(audio):
|
331 |
-
wav_file = open("audio/audio.wav", "wb")
|
332 |
-
wav_file.write(audio.tobytes())
|
333 |
-
wav_file.close()
|
334 |
-
|
335 |
-
audio_file= open("audio/audio.wav", "rb")
|
336 |
-
user_input = openai.Audio.transcribe("whisper-1", audio_file).text
|
337 |
-
audio_file.close()
|
338 |
-
return user_input
|
339 |
-
|
340 |
-
def page4():
|
341 |
-
|
342 |
-
# time
|
343 |
-
st.session_state.start_time = time.time()
|
344 |
-
|
345 |
-
with st.sidebar:
|
346 |
-
st.sidebar.title('Ask to GPT')
|
347 |
-
user_input = st.sidebar.text_area(
|
348 |
-
label="Question",
|
349 |
-
placeholder="Input text here",
|
350 |
-
height=100)
|
351 |
-
output = st.sidebar.button("Ask")
|
352 |
-
input_error_message = st.empty()
|
353 |
-
if output:
|
354 |
-
if not user_input:
|
355 |
-
input_error_message.error("Please enter your question")
|
356 |
-
result = ""
|
357 |
-
else:
|
358 |
-
result = gpt_call(user_input)
|
359 |
-
else:
|
360 |
-
result = ""
|
361 |
-
|
362 |
-
st.sidebar.text_area(
|
363 |
-
label="Answer",
|
364 |
-
placeholder="(Answer will be shown here)",
|
365 |
-
value=result,
|
366 |
-
height=150)
|
367 |
-
|
368 |
-
# default system prompt settings
|
369 |
-
if not st.session_state['total_debate_history']:
|
370 |
-
debate_preset = "\n".join([
|
371 |
-
"Debate Rules: ",
|
372 |
-
"1) This debate will be divided into two teams, pro and con, with two debates on each team.",
|
373 |
-
"2) The order of speaking is: first debater for the pro side, first debater for the con side, second debater for the pro side, second debater for the con side.",
|
374 |
-
"3) Answer logically with an introduction, body, and conclusion.", #add this one.
|
375 |
-
"4) Your role : " + st.session_state["pros_and_cons"] + " side debator",
|
376 |
-
"5) Debate subject: " + st.session_state['topic'],
|
377 |
-
])
|
378 |
-
first_prompt = "Now we're going to start. Summarize the subject and your role. And ask user ready to begin."
|
379 |
-
|
380 |
-
st.session_state['total_debate_history'] = [
|
381 |
-
{"role": "system", "content": debate_preset}
|
382 |
-
]
|
383 |
-
response = gpt_call(debate_preset + "\n" + first_prompt, role="system")
|
384 |
-
st.session_state['total_debate_history'].append({"role": "assistant", "content": response})
|
385 |
-
st.session_state['bot_debate_history'].append(response)
|
386 |
-
|
387 |
-
# container for chat history
|
388 |
-
response_container = st.container()
|
389 |
-
# container for text box
|
390 |
-
container = st.container()
|
391 |
-
|
392 |
-
with container:
|
393 |
-
with st.form(key='my_form', clear_on_submit=True):
|
394 |
-
user_input = None
|
395 |
-
# record voice
|
396 |
-
audio = audiorecorder("Click to record", "Recording...")
|
397 |
-
if np.array_equal(st.session_state['pre_audio'], audio):
|
398 |
-
audio = np.array([])
|
399 |
-
print("audio", audio)
|
400 |
-
|
401 |
-
#user_input = st.text_area("You:", key='input', height=100)
|
402 |
-
submit_buttom = st.form_submit_button(label='Send')
|
403 |
-
send_error_message = st.empty()
|
404 |
-
|
405 |
-
#if submit_buttom and user_input:
|
406 |
-
if submit_buttom:
|
407 |
-
if audio.any():
|
408 |
-
user_input = execute_stt(audio)
|
409 |
-
output = generate_response(user_input)
|
410 |
-
st.session_state['pre_audio'] = audio
|
411 |
-
else:
|
412 |
-
send_error_message.error("Please record your voice first", icon="🚨")
|
413 |
-
print("Nothing to transcribe")
|
414 |
-
|
415 |
-
#TODO 사용자 input이 없을 때도 reloading으로 buffering 걸리는 문제 해결
|
416 |
-
with response_container:
|
417 |
-
message(st.session_state['bot_debate_history'][0], key='0_bot')
|
418 |
-
text_to_speech = gTTS(text=st.session_state['bot_debate_history'][0], lang='en', slow=False)
|
419 |
-
text_to_speech.save(f'audio/test_gtts_0.mp3')
|
420 |
-
audio_file = open(f'audio/test_gtts_0.mp3', 'rb')
|
421 |
-
audio_bytes = audio_file.read()
|
422 |
-
st.audio(audio_bytes, format='audio/ogg')
|
423 |
-
|
424 |
-
for i in range(len(st.session_state['user_debate_history'])):
|
425 |
-
message(st.session_state['user_debate_history'][i], is_user=True, key=str(i)+'_user')
|
426 |
-
message(st.session_state['bot_debate_history'][i + 1], key=str(i + 1)+'_bot')
|
427 |
-
text_to_speech = gTTS(text=st.session_state['bot_debate_history'][i + 1], lang='en', slow=False)
|
428 |
-
text_to_speech.save(f'audio/test_gtts_{str(i + 1)}.mp3')
|
429 |
-
audio_file = open(f'audio/test_gtts_{str(i + 1)}.mp3', 'rb')
|
430 |
-
audio_bytes = audio_file.read()
|
431 |
-
st.audio(audio_bytes, format='audio/ogg')
|
432 |
-
|
433 |
-
if st.button(label="Next",
|
434 |
-
on_click=page_4_5_controller):
|
435 |
-
st.write('Information submitted successfully.')
|
436 |
-
|
437 |
-
print("#"*50)
|
438 |
-
print(st.session_state)
|
439 |
-
print("#"*50)
|
440 |
-
|
441 |
-
#########################################################
|
442 |
-
# Page5 - Total Debate Evaluation
|
443 |
-
#########################################################
|
444 |
-
def page5():
|
445 |
-
|
446 |
-
# end time
|
447 |
-
st.session_state.end_time = time.time()
|
448 |
-
st.session_state.debate_time = st.session_state.end_time - st.session_state.start_time
|
449 |
-
|
450 |
-
# st.tab
|
451 |
-
st.header('Total Debate Evaluation')
|
452 |
-
|
453 |
-
tab1, tab2 = st.tabs(['Debate Judgement', 'Debate Analysis'])
|
454 |
-
|
455 |
-
with tab1:
|
456 |
-
st.header("Debate Evaluation")
|
457 |
-
|
458 |
-
debate_themes = ['User-Bot', "User", "Bot"]
|
459 |
-
|
460 |
-
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
461 |
-
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
462 |
-
|
463 |
-
with st.spinner('Wait for judgement result...'):
|
464 |
-
judgement_result = ""
|
465 |
-
|
466 |
-
user_debate_history = "".join(
|
467 |
-
st.session_state.user_debate_history
|
468 |
-
)
|
469 |
-
bot_debate_history = "".join(
|
470 |
-
st.session_state.bot_debate_history
|
471 |
-
)
|
472 |
-
|
473 |
-
judgement_result = debate_judgement(
|
474 |
-
judgement_who,
|
475 |
-
user_debate_history,
|
476 |
-
bot_debate_history
|
477 |
-
)
|
478 |
-
|
479 |
-
st.write("Debate Judgement Result")
|
480 |
-
st.write(judgement_result)
|
481 |
-
st.success('Done!')
|
482 |
-
|
483 |
-
with tab2:
|
484 |
-
st.header('Debate Analysis')
|
485 |
-
|
486 |
-
# 유저의 history를 기반으로 발화량, 빈출 단어, 발화 습관 세 가지를 분석
|
487 |
-
user_history = st.session_state.user_debate_history
|
488 |
-
|
489 |
-
# 1. 발화량: 총 단어, 평균 속도(단어/시간)를 평균 발화량 혹은 참고 지표와 비교해 제시
|
490 |
-
|
491 |
-
# 총 단어
|
492 |
-
# 텍스트를 단어로 분할합니다.
|
493 |
-
# 각 단어의 빈도를 계산합니다.
|
494 |
-
total_word_count = len(user_history)
|
495 |
-
#total_word_count = len(user_history.split())
|
496 |
-
st.write("Total Word Count: ", total_word_count)
|
497 |
-
|
498 |
-
# 평균 속도(단어/시간)
|
499 |
-
#user_debate_time = st.session_state.user_debate_time
|
500 |
-
average_word_per_time = total_word_count / st.session_state.debate_time # 시간 단위보고 나중에 수정하기
|
501 |
-
st.write("Average Word Per Time: ", average_word_per_time)
|
502 |
-
|
503 |
-
# 2. 빈출 단어: 반복해서 사용하는 단어 리스트
|
504 |
-
# 빈도 계산
|
505 |
-
frequency = Counter(user_history)
|
506 |
-
# 가장 빈도가 높은 데이터 출력
|
507 |
-
most_common_data = frequency.most_common(10)
|
508 |
-
print(most_common_data)
|
509 |
-
st.write("Most Common Words: ", most_common_data)
|
510 |
-
|
511 |
-
# 3. 발화 습관: 불필요한 언어습관(아, 음)
|
512 |
-
# whisper preprocesser에서 주면
|
513 |
-
disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
|
514 |
-
# Count the disfluency words
|
515 |
-
disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
516 |
-
st.write("Disfluency Counts: ", disfluency_counts)
|
517 |
-
|
518 |
-
# 유저와 봇의 대화 데이터가 세션에 남아있음
|
519 |
-
# st.session_state.debate_history
|
520 |
-
|
521 |
-
|
522 |
-
#########################################################
|
523 |
-
# Page6
|
524 |
-
#########################################################
|
525 |
-
|
526 |
-
def page6():
|
527 |
-
|
528 |
-
# end time
|
529 |
-
st.session_state.end_time = time.time()
|
530 |
-
st.session_state.debate_time = st.session_state.end_time - st.session_state.start_time
|
531 |
-
|
532 |
-
# st.tab
|
533 |
-
st.header('Total Debate Evaluation')
|
534 |
-
|
535 |
-
tab1, tab2 = st.tabs(['Debate Judgement', 'Debate Analysis'])
|
536 |
-
|
537 |
-
with tab1:
|
538 |
-
st.header("Debate Evaluation")
|
539 |
-
|
540 |
-
debate_themes = ['User-Bot', "User", "Bot"]
|
541 |
-
|
542 |
-
# 전체, 유저, 봇 세 가지 옵션 중에 선택
|
543 |
-
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
544 |
-
|
545 |
-
judgement_result = ""
|
546 |
-
if judgement_result == "":
|
547 |
-
st.write("Wait for judgement result...")
|
548 |
-
|
549 |
-
user_debate_history = "".join(
|
550 |
-
st.session_state.user_debate_history
|
551 |
-
)
|
552 |
-
bot_debate_history = "".join(
|
553 |
-
st.session_state.bot_debate_history
|
554 |
-
)
|
555 |
-
|
556 |
-
judgement_result = debate_judgement(
|
557 |
-
judgement_who,
|
558 |
-
user_debate_history,
|
559 |
-
bot_debate_history
|
560 |
-
)
|
561 |
-
|
562 |
-
st.write("Debate Judgement Result")
|
563 |
-
st.write(judgement_result)
|
564 |
-
|
565 |
-
with tab2:
|
566 |
-
st.header('Debate Analysis')
|
567 |
-
|
568 |
-
# 유저의 history를 기반으로 발화량, 빈출 단어, 발화 습관 세 가지를 분석
|
569 |
-
user_history = st.session_state.user_debate_history
|
570 |
-
|
571 |
-
# 1. 발화량: 총 단어, 평균 속도(단어/시간)를 평균 발화량 혹은 참고 지표와 비교해 제시
|
572 |
-
|
573 |
-
# 총 단어
|
574 |
-
# 텍스트를 단어로 분할합니다.
|
575 |
-
# 각 단어의 빈도를 계산합니다.
|
576 |
-
total_word_count = len(user_history)
|
577 |
-
#total_word_count = len(user_history.split())
|
578 |
-
st.write("Total Word Count: ", total_word_count)
|
579 |
-
|
580 |
-
# 평균 속도(단어/시간)
|
581 |
-
#user_debate_time = st.session_state.user_debate_time
|
582 |
-
average_word_per_time = total_word_count / st.session_state.debate_time # 시간 단위보고 나중에 수정하기
|
583 |
-
st.write("Average Word Per Time: ", average_word_per_time)
|
584 |
-
|
585 |
-
# 2. 빈출 단어: 반복해서 사용하는 단어 리스트
|
586 |
-
# 빈도 계산
|
587 |
-
frequency = Counter(user_history)
|
588 |
-
# 가장 빈도가 높은 데이터 출력
|
589 |
-
most_common_data = frequency.most_common(10)
|
590 |
-
print(most_common_data)
|
591 |
-
st.write("Most Common Words: ", most_common_data)
|
592 |
-
|
593 |
-
# 3. 발화 습관: 불필요한 언어습관(아, 음)
|
594 |
-
# whisper preprocesser에서 주면
|
595 |
-
disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
|
596 |
-
# Count the disfluency words
|
597 |
-
disfluency_counts = sum(user_word in disfluency_word_list for user_word in user_history)
|
598 |
-
st.write("Disfluency Counts: ", disfluency_counts)
|
599 |
-
|
600 |
-
# 유저와 봇의 대화 데이터가 세션에 남아있음
|
601 |
-
# st.session_state.debate_history
|
602 |
-
|
603 |
-
############################################
|
604 |
-
# Visualization
|
605 |
-
############################################
|
606 |
-
|
607 |
-
# 이전에 기록된 값이 있다면, 그래프를 그립니다.
|
608 |
-
# 이전에 기록된 값이 없다면, 그래프를 그리지 않습니다.
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
#########################################################
|
613 |
-
# Page Routing
|
614 |
-
#########################################################
|
615 |
-
pages = {
|
616 |
-
"Page 1": page1, # user_id와 openai_key를 입력받는 페이지
|
617 |
-
"Page 2": page2, # 원하는 ��능을 선택하는 페이지
|
618 |
-
"Page 3": page3, # Total Debate
|
619 |
-
"Page 4": page4, # Evaluation Only
|
620 |
-
"Page 5": page5, # Analyzing Utterances
|
621 |
-
"Page 6": page6,
|
622 |
-
}
|
623 |
-
|
624 |
-
selection = st.session_state.page
|
625 |
-
print("selection:", selection)
|
626 |
-
|
627 |
-
page = pages[selection]
|
628 |
-
# Execute selected page function
|
629 |
-
page()
|
630 |
-
|
631 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vocal_app.sh
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
streamlit run vocal_app.py
|
|
|
|