Skip to content

Commit

Permalink
Record answer samples with tts, save score result to json, remove ugl…
Browse files Browse the repository at this point in the history
…y beep sound and play tts answers instead
  • Loading branch information
pskl committed Nov 28, 2023
1 parent 7a2d6c9 commit 758bb0f
Show file tree
Hide file tree
Showing 61 changed files with 70 additions and 52 deletions.
Binary file removed docs/answer.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_1.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_10.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_11.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_12.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_13.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_14.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_15.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_16.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_17.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_18.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_19.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_2.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_20.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_21.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_22.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_23.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_24.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_25.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_26.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_27.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_28.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_29.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_3.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_30.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_31.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_32.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_33.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_34.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_35.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_36.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_37.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_38.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_39.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_4.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_40.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_41.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_42.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_43.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_44.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_45.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_46.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_47.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_48.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_49.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_5.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_50.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_6.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_7.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_8.mp3
Binary file not shown.
Binary file modified docs/answers/interlink_mistral_big5/speech/question_9.mp3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
{
"index": 1,
"question": "Am the life of the party.",
"sample": 3
"sample": 1
},
{
"index": 2,
"question": "Feel little concern for others.",
"sample": 2
"sample": 5
},
{
"index": 3,
Expand All @@ -21,12 +21,12 @@
{
"index": 4,
"question": "Get stressed out easily.",
"sample": 2
"sample": 1
},
{
"index": 5,
"question": "Have a rich vocabulary.",
"sample": 1
"sample": 4
},
{
"index": 6,
Expand All @@ -46,17 +46,17 @@
{
"index": 9,
"question": "Am relaxed most of the time.",
"sample": 3
"sample": 4
},
{
"index": 10,
"question": "Have difficulty understanding abstract ideas.",
"sample": 4
"sample": 5
},
{
"index": 11,
"question": "Feel comfortable around people.",
"sample": 5
"sample": 1
},
{
"index": 12,
Expand All @@ -76,7 +76,7 @@
{
"index": 15,
"question": "Have a vivid imagination.",
"sample": 5
"sample": 1
},
{
"index": 16,
Expand All @@ -86,17 +86,17 @@
{
"index": 17,
"question": "Sympathize with others' feelings.",
"sample": 3
"sample": 1
},
{
"index": 18,
"question": "Make a mess of things.",
"sample": 5
"sample": 1
},
{
"index": 19,
"question": "Seldom feel blue.",
"sample": 1
"sample": 3
},
{
"index": 20,
Expand All @@ -106,27 +106,27 @@
{
"index": 21,
"question": "Start conversations.",
"sample": 2
"sample": 1
},
{
"index": 22,
"question": "Am not interested in other people's problems.",
"sample": 5
"sample": 1
},
{
"index": 23,
"question": "Get chores done right away.",
"sample": 4
"sample": 3
},
{
"index": 24,
"question": "Am easily disturbed.",
"sample": 5
"sample": 2
},
{
"index": 25,
"question": "Have excellent ideas.",
"sample": 4
"sample": 5
},
{
"index": 26,
Expand All @@ -136,7 +136,7 @@
{
"index": 27,
"question": "Have a soft heart.",
"sample": 3
"sample": 4
},
{
"index": 28,
Expand All @@ -146,32 +146,32 @@
{
"index": 29,
"question": "Get upset easily.",
"sample": 5
"sample": 1
},
{
"index": 30,
"question": "Do not have a good imagination.",
"sample": 5
"sample": 2
},
{
"index": 31,
"question": "Talk to a lot of different people at parties.",
"sample": 3
"sample": 2
},
{
"index": 32,
"question": "Am not really interested in others.",
"sample": 5
"sample": 2
},
{
"index": 33,
"question": "Like order.",
"sample": 1
"sample": 4
},
{
"index": 34,
"question": "Change my mood a lot.",
"sample": 5
"sample": 4
},
{
"index": 35,
Expand All @@ -181,7 +181,7 @@
{
"index": 36,
"question": "Don't like to draw attention to myself.",
"sample": 5
"sample": 3
},
{
"index": 37,
Expand All @@ -196,17 +196,17 @@
{
"index": 39,
"question": "Have frequent mood swings.",
"sample": 5
"sample": 2
},
{
"index": 40,
"question": "Use difficult words.",
"sample": 1
"sample": 3
},
{
"index": 41,
"question": "Don't mind being the center of attention.",
"sample": 1
"sample": 4
},
{
"index": 42,
Expand All @@ -216,17 +216,17 @@
{
"index": 43,
"question": "Follow a schedule.",
"sample": 1
"sample": 3
},
{
"index": 44,
"question": "Get irritated easily.",
"sample": 3
"sample": 2
},
{
"index": 45,
"question": "Spend time reflecting on things.",
"sample": 1
"sample": 3
},
{
"index": 46,
Expand All @@ -241,17 +241,24 @@
{
"index": 48,
"question": "Am exacting in my work.",
"sample": 1
"sample": 3
},
{
"index": 49,
"question": "Often feel blue.",
"sample": 5
"sample": 4
},
{
"index": 50,
"question": "Am full of ideas.",
"sample": 3
"sample": 4
}
]
],
"score": {
"Extraversion": 52,
"Agreeableness": 38,
"Conscientiousness": 42,
"Neuroticism": 66,
"Openness": 41
}
}
13 changes: 6 additions & 7 deletions docs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var lineGenerator = d3.line().curve(d3.curveBasis)
.y(function (d) { return yScale(d.y) });

document.getElementById('startButton').addEventListener('click', function () {
fetch(`${folderPath}/test_2719711939644891597.json`)
fetch(`${folderPath}/test_8346320627440787020.json`)
.then(response => response.json())
.then(data => {
displayBanner(data);
Expand Down Expand Up @@ -49,11 +49,10 @@ function playAudioForQuestion(index) {
return audio;
}

function playBeep(answerNumber) {
const beepAudio = new Audio('./answer.mp3');
beepAudio.playbackRate = 1 / (answerNumber); // smaller answerNumber will yield higher pitch
beepAudio.play().catch(console.error);
return beepAudio;
function playAnswer(answerNumber) {
const answerAudio = new Audio(`${folderPath}/speech/answer_${answerNumber}.mp3`);
answerAudio.play().catch(console.error);
return answerAudio;
}


Expand Down Expand Up @@ -90,7 +89,7 @@ function displayChat(answers) {
.onended = () => {
displayAnswer(answers[i], container);
scrollToBottom(container);
playBeep(parseFloat(answers[i].sample)).onended = () => {
playAnswer(answers[i].sample).onended = () => {
scrollToBottom(container);
const img = images[i];
img.style.display = 'inline-block';
Expand Down
9 changes: 8 additions & 1 deletion lib/bigfive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ def score(self, answers):
if len(answers) < 49:
raise IndexError("Not enough answers to score properly")
else:
res = {}
E = 20 + answers[0] + answers[5] + answers[10] + answers[15] + answers[20] + answers[25] + answers[30] + answers[35] + answers[40] + answers[45]
print(f"Extraversion: {E}")
res["Extraversion"] = E
A = 14 + answers[1] + answers[6] + answers[11] + answers[16] + answers[21] + answers[26] + answers[31] + answers[36] + answers[41] + answers[46]
print(f"Agreeableness: {A}")
res["Agreeableness"] = A
C = 14 + answers[2] + answers[7] + answers[12] + answers[17] + answers[22] + answers[27] + answers[32] + answers[37] + answers[42] + answers[47]
print(f"Conscientiousness: {C}")
res["Conscientiousness"] = C
N = 38 + answers[3] + answers[8] + answers[13] + answers[18] + answers[23] + answers[28] + answers[33] + answers[38] + answers[43] + answers[48]
print(f"Neuroticism: {N}")
res["Neuroticism"] = N
O = 8 + answers[4] + answers[9] + answers[14] + answers[19] + answers[24] + answers[29] + answers[34] + answers[39] + answers[44] + answers[49]
print(f"Openness: {O}")
print(f"Openness: {O}")
res["Openness"] = O
return res
5 changes: 4 additions & 1 deletion lib/pid5.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def reverse_answer(self, answer):

def score(self, answers):
average_scores = {}
res = {}
for word, indices in Pid5.WORD_SCORES.items():
total = sum(answers[i - 1] for i in indices if i - 1 < len(answers))
average_score = total / len(indices)
Expand All @@ -56,4 +57,6 @@ def score(self, answers):
for domain, components in sorted(Pid5.DOMAIN_SCORES.items(), key=lambda x: x[0]):
total = sum(average_scores[component] for component in components)
average = total / len(components)
print(f"The domain score for {domain} is {round(average, 2)}")
print(f"The domain score for {domain} is {round(average, 2)}")
res[domain] = round(average, 2)
return res
20 changes: 11 additions & 9 deletions lib/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def answer(self):
answer = self.implementation.ask_question(question, self.prompt, self.model)

if self.tts:
self.generate_tts(question, i)
self.generate_tts(question, i, 'nova', 'question')
self.generate_tts(answer, answer, 'onyx', 'answer')

if self.image:
self.generate_image(question, answer, i)
Expand All @@ -48,18 +49,19 @@ def answer(self):
print(f'Question {i}: {question}')
print(f'Answer: {answer}\n')

self.serialize(questions, answers)
self.score(answers)
score = self.score(answers)
self.serialize(questions, answers, score)

# Save test run to json file so that it can be replayed without triggering HTTP requests
def serialize(self, questions, answers):
def serialize(self, questions, answers, score):
os.makedirs(self.answer_folder_path(), exist_ok=True)
json_file = f'{self.answer_folder_path()}/test_{self.seed}.json'
result = {
"model": self.model,
"test": self.__class__.ID,
"prompt": self.prompt,
"answers": []
"answers": [],
"score": score
}
for i, answer in enumerate(answers, start=1):
result["answers"].append({
Expand All @@ -73,15 +75,15 @@ def serialize(self, questions, answers):
except Exception as e:
print("Error writing to file: ", e)

def generate_tts(self, question, index):
def generate_tts(self, text, index, voice, text_type):
speech_path = f"{self.answer_folder_path()}/speech/"
os.makedirs(speech_path, exist_ok=True)
speech_file_path = f"{speech_path}/question_{index}.mp3"
speech_file_path = f"{speech_path}/{text_type}_{index}.mp3"
if not os.path.exists(speech_file_path):
response = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")).audio.speech.create(
model="tts-1",
voice="nova",
input=question
voice=voice,
input=text
)
response.stream_to_file(speech_file_path)

Expand Down

0 comments on commit 758bb0f

Please sign in to comment.