Update abc.txt
Browse files
abc.txt
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,29 @@ 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')
|
@@ -115,15 +139,54 @@ 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 |
|
121 |
# Main function to display the app
|
122 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
if api_key:
|
124 |
show_mbti_quiz()
|
125 |
else:
|
126 |
st.info("Please enter your OpenAI API Key to begin the quiz.")
|
127 |
|
128 |
if __name__ == "__main__":
|
129 |
-
main()
|
|
|
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 |
+
# Function to save personality results to Output.json
|
86 |
+
def save_personality_to_output_json(username, mbti_type_classic, mbti_type_llm):
|
87 |
+
output_data = {
|
88 |
+
"username": username,
|
89 |
+
"mbti_type_classic": mbti_type_classic,
|
90 |
+
"mbti_type_llm": mbti_type_llm
|
91 |
+
}
|
92 |
+
|
93 |
+
# Save to Output.json
|
94 |
+
with open("Output.json", "w") as json_file:
|
95 |
+
json.dump(output_data, json_file, indent=4)
|
96 |
+
|
97 |
# Streamlit component to display the quiz and handle responses
|
98 |
def show_mbti_quiz():
|
99 |
st.title('FlexTemp Personality Test')
|
|
|
139 |
st.write(f"Your MBTI type according to AI: {mbti_type_llm}")
|
140 |
except Exception as e:
|
141 |
st.error(f"Error occurred: {e}")
|
142 |
+
|
143 |
+
# Save responses and personality info to Output.json
|
144 |
+
save_responses_to_json(participant_name, responses)
|
145 |
+
save_personality_to_output_json(participant_name, mbti_type_classic, mbti_type_llm)
|
146 |
+
|
147 |
+
with open("Output.json", "r") as json_file:
|
148 |
+
json_data = json_file.read()
|
149 |
+
|
150 |
+
st.download_button(
|
151 |
+
label="Download Output.json",
|
152 |
+
data=json_data,
|
153 |
+
file_name="Output.json",
|
154 |
+
mime="application/json"
|
155 |
+
)
|
156 |
+
|
157 |
+
with open("UserChoices.json", "r") as json_file:
|
158 |
+
json_data = json_file.read()
|
159 |
+
|
160 |
+
st.download_button(
|
161 |
+
label="Download UserChoices.json",
|
162 |
+
data=json_data,
|
163 |
+
file_name="UserChoices.json",
|
164 |
+
mime="application/json"
|
165 |
+
)
|
166 |
+
|
167 |
else:
|
168 |
st.warning("Please answer all the questions!")
|
169 |
|
170 |
# Main function to display the app
|
171 |
def main():
|
172 |
+
# Add instructions to the sidebar
|
173 |
+
with st.sidebar.expander("How This App Works", expanded=False):
|
174 |
+
st.write("""
|
175 |
+
### FlexTemp Personality Test
|
176 |
+
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:
|
177 |
+
1. **Weighted MBTI Scoring**:
|
178 |
+
- Each question corresponds to a trait in the MBTI system.
|
179 |
+
- Your responses are scored on a scale from "Strongly Agree" to "Strongly Disagree", with each level being assigned a weight.
|
180 |
+
- These weights are used to calculate your MBTI type by comparing the scores of trait pairs (E/I, S/N, T/F, J/P).
|
181 |
+
2. **LLM-Based Prediction**:
|
182 |
+
- 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.
|
183 |
+
- The LLM is trained on vast amounts of data and can generate responses based on patterns from psychological research and real-world interactions.
|
184 |
+
""")
|
185 |
+
|
186 |
if api_key:
|
187 |
show_mbti_quiz()
|
188 |
else:
|
189 |
st.info("Please enter your OpenAI API Key to begin the quiz.")
|
190 |
|
191 |
if __name__ == "__main__":
|
192 |
+
main()
|