shukdevdatta123 commited on
Commit
c92ec5b
·
verified ·
1 Parent(s): 15e6faf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -90,32 +90,31 @@ def show_mbti_quiz():
90
  responses.append(response)
91
 
92
  if len(responses) == len(questions):
93
- st.subheader("Your MBTI Personality Type:")
94
- mbti_type_classic = classic_mbti_weighted(responses)
95
- st.write(f"Your MBTI type based on weighted answers: {mbti_type_classic}")
96
-
97
- # You can add LLM-based prediction if needed here (example OpenAI-based model)
98
- if api_key:
99
- # Run the LLM (GPT-4, for example) model to generate a personality type.
100
- prompt = f"""
101
- Determine a person's personality type based on their answers to the following Myers-Briggs Type Indicator (MBTI) questions:
102
- The person has answered the following questions:
103
-
104
- {', '.join([f"{question['text']} {response}" for question, response in zip(questions, responses)])}
105
-
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
-
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