Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
-
|
4 |
import os
|
|
|
5 |
|
6 |
# Load the OpenAI API Key
|
7 |
api_key = st.text_input('Enter your OpenAI API Key', type="password")
|
@@ -70,6 +71,17 @@ def classic_mbti_weighted(responses):
|
|
70 |
mbti_type += trait2
|
71 |
return mbti_type
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
# Streamlit component to display the quiz and handle responses
|
74 |
def show_mbti_quiz():
|
75 |
st.title('FlexTemp Personality Test')
|
@@ -107,7 +119,7 @@ def show_mbti_quiz():
|
|
107 |
"""
|
108 |
try:
|
109 |
response = openai.ChatCompletion.create(
|
110 |
-
model="gpt-
|
111 |
messages=[{"role": "system", "content": "You are a helpful assistant."},
|
112 |
{"role": "user", "content": prompt}]
|
113 |
)
|
@@ -115,6 +127,19 @@ def show_mbti_quiz():
|
|
115 |
st.write(f"Your MBTI type according to AI: {mbti_type_llm}")
|
116 |
except Exception as e:
|
117 |
st.error(f"Error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
else:
|
119 |
st.warning("Please answer all the questions!")
|
120 |
|
@@ -125,12 +150,10 @@ def main():
|
|
125 |
st.write("""
|
126 |
### FlexTemp Personality Test
|
127 |
This app is designed to help you determine your MBTI personality type based on your answers to a series of questions. The process works as follows:
|
128 |
-
|
129 |
1. **Weighted MBTI Scoring**:
|
130 |
- Each question corresponds to a trait in the MBTI system.
|
131 |
- Your responses are scored on a scale from "Strongly Agree" to "Strongly Disagree", with each level being assigned a weight.
|
132 |
- These weights are used to calculate your MBTI type by comparing the scores of trait pairs (E/I, S/N, T/F, J/P).
|
133 |
-
|
134 |
2. **LLM-Based Prediction**:
|
135 |
- Optionally, you can also get your MBTI type based on the answers using a language model (LLM) like GPT-4. This provides an additional prediction that may offer insights into your personality.
|
136 |
- The LLM is trained on vast amounts of data and can generate responses based on patterns from psychological research and real-world interactions.
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
+
import json
|
4 |
import os
|
5 |
+
from dotenv import load_dotenv
|
6 |
|
7 |
# Load the OpenAI API Key
|
8 |
api_key = st.text_input('Enter your OpenAI API Key', type="password")
|
|
|
71 |
mbti_type += trait2
|
72 |
return mbti_type
|
73 |
|
74 |
+
# Function to save responses to a JSON file
|
75 |
+
def save_responses_to_json(username, responses):
|
76 |
+
user_data = {
|
77 |
+
"username": username,
|
78 |
+
"responses": [{"text": question["text"], "answer": response} for question, response in zip(questions, responses)]
|
79 |
+
}
|
80 |
+
|
81 |
+
# Save to UserChoices.json
|
82 |
+
with open("UserChoices.json", "w") as json_file:
|
83 |
+
json.dump(user_data, json_file, indent=4)
|
84 |
+
|
85 |
# Streamlit component to display the quiz and handle responses
|
86 |
def show_mbti_quiz():
|
87 |
st.title('FlexTemp Personality Test')
|
|
|
119 |
"""
|
120 |
try:
|
121 |
response = openai.ChatCompletion.create(
|
122 |
+
model="gpt-4",
|
123 |
messages=[{"role": "system", "content": "You are a helpful assistant."},
|
124 |
{"role": "user", "content": prompt}]
|
125 |
)
|
|
|
127 |
st.write(f"Your MBTI type according to AI: {mbti_type_llm}")
|
128 |
except Exception as e:
|
129 |
st.error(f"Error occurred: {e}")
|
130 |
+
|
131 |
+
# Save responses and allow download of UserChoices.json
|
132 |
+
save_responses_to_json(participant_name, responses)
|
133 |
+
with open("UserChoices.json", "r") as json_file:
|
134 |
+
json_data = json_file.read()
|
135 |
+
|
136 |
+
st.download_button(
|
137 |
+
label="Download UserChoices",
|
138 |
+
data=json_data,
|
139 |
+
file_name="UserChoices.json",
|
140 |
+
mime="application/json"
|
141 |
+
)
|
142 |
+
|
143 |
else:
|
144 |
st.warning("Please answer all the questions!")
|
145 |
|
|
|
150 |
st.write("""
|
151 |
### FlexTemp Personality Test
|
152 |
This app is designed to help you determine your MBTI personality type based on your answers to a series of questions. The process works as follows:
|
|
|
153 |
1. **Weighted MBTI Scoring**:
|
154 |
- Each question corresponds to a trait in the MBTI system.
|
155 |
- Your responses are scored on a scale from "Strongly Agree" to "Strongly Disagree", with each level being assigned a weight.
|
156 |
- These weights are used to calculate your MBTI type by comparing the scores of trait pairs (E/I, S/N, T/F, J/P).
|
|
|
157 |
2. **LLM-Based Prediction**:
|
158 |
- Optionally, you can also get your MBTI type based on the answers using a language model (LLM) like GPT-4. This provides an additional prediction that may offer insights into your personality.
|
159 |
- The LLM is trained on vast amounts of data and can generate responses based on patterns from psychological research and real-world interactions.
|