Spaces:
Runtime error
Runtime error
Merge remote-tracking branch 'upstream/master' into page_4to6_ui
Browse files- bots/judgement_bot.py +27 -0
- vocal_app.py +115 -11
- whisper_app.py +4 -0
bots/judgement_bot.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from modules.gpt_modules import gpt_call
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
|
4 |
+
def debate_judgement(debate_history):
|
5 |
+
|
6 |
+
judgement_prompt = "\n".join([
|
7 |
+
"!!Instruction!",
|
8 |
+
"You are now the judge of this debate. Evaluate the debate according to the rules below.",
|
9 |
+
"Rule 1. Decide between the USER and BOT.",
|
10 |
+
"Rule 2. Summarize the debate as a whole and what each debater said.",
|
11 |
+
"Rule 3. For each debater, explain what was persuasive and what made the differnce between winning and losing.",
|
12 |
+
])
|
13 |
+
|
14 |
+
judgement_prompt_template = PromptTemplate(
|
15 |
+
input_variables=["prompt"],
|
16 |
+
template="\n".join([
|
17 |
+
debate_history,
|
18 |
+
judgement_prompt,
|
19 |
+
"Judgement: "
|
20 |
+
])
|
21 |
+
)
|
22 |
+
judgement_bot_prompt = judgement_prompt_template.format(
|
23 |
+
prompt=""
|
24 |
+
)
|
25 |
+
bot_response = gpt_call(judgement_bot_prompt)
|
26 |
+
|
27 |
+
return bot_response
|
vocal_app.py
CHANGED
@@ -3,6 +3,12 @@ import openai
|
|
3 |
|
4 |
from dotenv import dotenv_values
|
5 |
from streamlit_chat import message
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
#import SessionState
|
7 |
|
8 |
# Page Configuration
|
@@ -32,6 +38,21 @@ if "case3" not in st.session_state:
|
|
32 |
if "page2_tab" not in st.session_state:
|
33 |
st.session_state.page2_tab = "tab1"
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Initialize session state variables
|
37 |
if 'generated' not in st.session_state:
|
@@ -78,6 +99,9 @@ def page2_tab_controller():
|
|
78 |
def page4_controller():
|
79 |
st.session_state.page = "Page 4"
|
80 |
|
|
|
|
|
|
|
81 |
#########################################################
|
82 |
# Page 1
|
83 |
#########################################################
|
@@ -220,6 +244,8 @@ def page3():
|
|
220 |
height=100
|
221 |
)
|
222 |
|
|
|
|
|
223 |
st.button(
|
224 |
"Start Debate",
|
225 |
on_click=page4_controller
|
@@ -325,17 +351,93 @@ def page4():
|
|
325 |
print(st.session_state)
|
326 |
|
327 |
#########################################################
|
328 |
-
# Page5
|
329 |
#########################################################
|
330 |
def page5():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
|
332 |
-
with st.sidebar:
|
333 |
-
st.sidebar.title('Ask to GPT')
|
334 |
-
st.sidebar.text_area(
|
335 |
-
label="Input text here",
|
336 |
-
placeholder="Input text here",
|
337 |
-
height=100)
|
338 |
-
st.sidebar.button("Ask")
|
339 |
|
340 |
|
341 |
#########################################################
|
@@ -345,9 +447,11 @@ pages = {
|
|
345 |
"Page 1": page1, # user_id์ openai_key๋ฅผ ์
๋ ฅ๋ฐ๋ ํ์ด์ง
|
346 |
"Page 2": page2, # ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ๋ ํ์ด์ง
|
347 |
"Page 3": page3, # Total Debate
|
348 |
-
"Page 4": page4, #
|
349 |
-
"Page 5": page5, #
|
350 |
-
|
|
|
|
|
351 |
}
|
352 |
|
353 |
selection = st.session_state.page
|
|
|
3 |
|
4 |
from dotenv import dotenv_values
|
5 |
from streamlit_chat import message
|
6 |
+
from modules.gpt_modules import gpt_call
|
7 |
+
from langchain.prompts import PromptTemplate
|
8 |
+
from bots.judgement_bot import debate_judgement
|
9 |
+
import numpy as np
|
10 |
+
from collections import Counter
|
11 |
+
import re
|
12 |
#import SessionState
|
13 |
|
14 |
# Page Configuration
|
|
|
38 |
if "page2_tab" not in st.session_state:
|
39 |
st.session_state.page2_tab = "tab1"
|
40 |
|
41 |
+
if "total_debate_history" not in st.session_state:
|
42 |
+
st.session_state.total_debate_history = ""
|
43 |
+
|
44 |
+
if "user_debate_history" not in st.session_state:
|
45 |
+
st.session_state.user_debate_history = ""
|
46 |
+
|
47 |
+
if "bot_debate_history" not in st.session_state:
|
48 |
+
st.session_state.bot_debate_history = ""
|
49 |
+
|
50 |
+
if "user_debate_time" not in st.session_state:
|
51 |
+
st.session_state.user_debate_time = ""
|
52 |
+
|
53 |
+
if "pros_and_cons" not in st.session_state:
|
54 |
+
st.session_state.pros_and_cons = ""
|
55 |
+
|
56 |
|
57 |
# Initialize session state variables
|
58 |
if 'generated' not in st.session_state:
|
|
|
99 |
def page4_controller():
|
100 |
st.session_state.page = "Page 4"
|
101 |
|
102 |
+
def page_5_6_controller():
|
103 |
+
st.session_state.page = "Page 6"
|
104 |
+
|
105 |
#########################################################
|
106 |
# Page 1
|
107 |
#########################################################
|
|
|
244 |
height=100
|
245 |
)
|
246 |
|
247 |
+
st.session_state.pros_and_cons = st.selectbox("Choose your Side (Pros and Cons)", ["Pros", "Cons"])
|
248 |
+
|
249 |
st.button(
|
250 |
"Start Debate",
|
251 |
on_click=page4_controller
|
|
|
351 |
print(st.session_state)
|
352 |
|
353 |
#########################################################
|
354 |
+
# Page5 - Total Debate Evaluation
|
355 |
#########################################################
|
356 |
def page5():
|
357 |
+
st.header('Debate Judgement')
|
358 |
+
# ์ ์ ์ ๋ด์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์ธ์
์ ๋จ์์์
|
359 |
+
# st.session_state.debate_history
|
360 |
+
|
361 |
+
debate_themes = ['User-Bot', "User", "Bot"]
|
362 |
+
|
363 |
+
# ์ ์ฒด, ์ ์ , ๋ด ์ธ ๊ฐ์ง ์ต์
์ค์ ์ ํ
|
364 |
+
judgement_who = st.selectbox("Choose your debate theme", debate_themes)
|
365 |
+
|
366 |
+
if judgement_who == 'User-Bot':
|
367 |
+
debate_history = st.session_state.total_debate_history
|
368 |
+
elif judgement_who == 'User':
|
369 |
+
debate_history = st.session_state.user_debate_history
|
370 |
+
elif judgement_who == 'Bot':
|
371 |
+
debate_history = st.session_state.bot_debate_history
|
372 |
+
|
373 |
+
judgement_result = debate_judgement(debate_history)
|
374 |
+
|
375 |
+
st.write("Debate Judgement Result")
|
376 |
+
st.write(judgement_result)
|
377 |
+
|
378 |
+
st.button(
|
379 |
+
label='Move to Debate Dashboard',
|
380 |
+
on_click=page_5_6_controller
|
381 |
+
)
|
382 |
+
|
383 |
+
#########################################################
|
384 |
+
# Page6
|
385 |
+
#########################################################
|
386 |
+
|
387 |
+
def page6():
|
388 |
+
|
389 |
+
st.header('Debate Analysis')
|
390 |
+
|
391 |
+
# ์ ์ ์ history๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ฐํ๋, ๋น์ถ ๋จ์ด, ๋ฐํ ์ต๊ด ์ธ ๊ฐ์ง๋ฅผ ๋ถ์
|
392 |
+
user_history = st.session_state.user_debate_history
|
393 |
+
|
394 |
+
# 1. ๋ฐํ๋: ์ด ๋จ์ด, ํ๊ท ์๋(๋จ์ด/์๊ฐ)๋ฅผ ํ๊ท ๋ฐํ๋ ํน์ ์ฐธ๊ณ ์งํ์ ๋น๊ตํด ์ ์
|
395 |
+
|
396 |
+
# ์ด ๋จ์ด
|
397 |
+
# ํ
์คํธ๋ฅผ ๋จ์ด๋ก ๋ถํ ํฉ๋๋ค.
|
398 |
+
words = user_history.split()
|
399 |
+
# ๊ฐ ๋จ์ด์ ๋น๋๋ฅผ ๊ณ์ฐํฉ๋๋ค.
|
400 |
+
total_word_count = Counter(words)
|
401 |
+
#total_word_count = len(user_history.split())
|
402 |
+
|
403 |
+
# ํ๊ท ์๋(๋จ์ด/์๊ฐ)
|
404 |
+
user_debate_time = st.session_state.user_debate_time
|
405 |
+
average_word_per_time = total_word_count / user_debate_time # ์๊ฐ ๋จ์๋ณด๊ณ ๋์ค์ ์์ ํ๊ธฐ
|
406 |
+
|
407 |
+
# 2. ๋น์ถ ๋จ์ด: ๋ฐ๋ณตํด์ ์ฌ์ฉํ๋ ๋จ์ด ๋ฆฌ์คํธ
|
408 |
+
# ๋น๋๊ฐ ๋์ ์์๋๋ก ๋จ์ด๋ฅผ ์ ๋ ฌํฉ๋๋ค.
|
409 |
+
most_common_words = total_word_count.most_common()
|
410 |
+
# for word, count in most_common_words:
|
411 |
+
# print(f"'{word}': {count}")
|
412 |
+
|
413 |
+
# 3. ๋ฐํ ์ต๊ด: ๋ถํ์ํ ์ธ์ด์ต๊ด(์, ์)
|
414 |
+
# ๋ถํ์ํ ์ธ์ด์ต๊ด์ ์ ๊ทํํ์์ผ๋ก ์ฐพ์๋ด๊ธฐ
|
415 |
+
# whisper preprocesser์์ ์ฃผ๋ฉด
|
416 |
+
disfluency_word_list = ['eh', 'umm', 'ah', 'uh', 'er', 'erm', 'err']
|
417 |
+
# Count the disfluency words
|
418 |
+
disfluency_counts = {word: total_word_count[word] for word in disfluency_word_list}
|
419 |
+
|
420 |
+
|
421 |
+
|
422 |
+
|
423 |
+
|
424 |
+
|
425 |
+
pass
|
426 |
+
|
427 |
+
|
428 |
+
#########################################################
|
429 |
+
# Page7
|
430 |
+
#########################################################
|
431 |
+
def page7():
|
432 |
+
pass
|
433 |
+
|
434 |
+
|
435 |
+
#########################################################
|
436 |
+
# Page8
|
437 |
+
#########################################################
|
438 |
+
def page8():
|
439 |
+
pass
|
440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
|
442 |
|
443 |
#########################################################
|
|
|
447 |
"Page 1": page1, # user_id์ openai_key๋ฅผ ์
๋ ฅ๋ฐ๋ ํ์ด์ง
|
448 |
"Page 2": page2, # ์ํ๋ ๊ธฐ๋ฅ์ ์ ํํ๋ ํ์ด์ง
|
449 |
"Page 3": page3, # Total Debate
|
450 |
+
"Page 4": page4, # Evaluation Only
|
451 |
+
"Page 5": page5, # Analyzing Utterances
|
452 |
+
"Page 6": page6,
|
453 |
+
"Page 7": page7,
|
454 |
+
"Page 8": page8
|
455 |
}
|
456 |
|
457 |
selection = st.session_state.page
|
whisper_app.py
CHANGED
@@ -24,6 +24,10 @@ def debate(audio):
|
|
24 |
# user_words
|
25 |
user_prompt = openai.Audio.transcribe("whisper-1", file).text
|
26 |
|
|
|
|
|
|
|
|
|
27 |
# ์ผ๋จ ํ
์คํธ๋ฅผ ์ํด ๊ณ ์ ํจ
|
28 |
debate_subject = "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."
|
29 |
|
|
|
24 |
# user_words
|
25 |
user_prompt = openai.Audio.transcribe("whisper-1", file).text
|
26 |
|
27 |
+
print("**************************************")
|
28 |
+
print("user_audio transcription", user_prompt)
|
29 |
+
print("**************************************")
|
30 |
+
|
31 |
# ์ผ๋จ ํ
์คํธ๋ฅผ ์ํด ๊ณ ์ ํจ
|
32 |
debate_subject = "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."
|
33 |
|