Update app.py
Browse files
app.py
CHANGED
@@ -90,32 +90,31 @@ def show_mbti_quiz():
|
|
90 |
responses.append(response)
|
91 |
|
92 |
if len(responses) == len(questions):
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
#
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
else:
|
120 |
st.warning("Please answer all the questions!")
|
121 |
|
|
|
90 |
responses.append(response)
|
91 |
|
92 |
if len(responses) == len(questions):
|
93 |
+
# Add a button to generate personality information
|
94 |
+
if st.button("Generate Personality Trait Information"):
|
95 |
+
st.subheader("Your MBTI Personality Type:")
|
96 |
+
mbti_type_classic = classic_mbti_weighted(responses)
|
97 |
+
st.write(f"Your MBTI type based on weighted answers: {mbti_type_classic}")
|
98 |
+
|
99 |
+
# You can add LLM-based prediction if needed here (example OpenAI-based model)
|
100 |
+
if api_key:
|
101 |
+
# Run the LLM (GPT-4, for example) model to generate a personality type.
|
102 |
+
prompt = f"""
|
103 |
+
Determine a person's personality type based on their answers to the following Myers-Briggs Type Indicator (MBTI) questions:
|
104 |
+
The person has answered the following questions:
|
105 |
+
{', '.join([f"{question['text']} {response}" for question, response in zip(questions, responses)])}
|
106 |
+
What is the MBTI personality type based on these answers?
|
107 |
+
"""
|
108 |
+
try:
|
109 |
+
response = openai.ChatCompletion.create(
|
110 |
+
model="gpt-4o",
|
111 |
+
messages=[{"role": "system", "content": "You are a helpful assistant."},
|
112 |
+
{"role": "user", "content": prompt}]
|
113 |
+
)
|
114 |
+
mbti_type_llm = response['choices'][0]['message']['content']
|
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 |
|