Update app.py
Browse files
app.py
CHANGED
@@ -51,6 +51,93 @@ questions = [
|
|
51 |
"44. Knows a lot about art, music and books"
|
52 |
]
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Scoring function based on the provided SPSS syntax
|
55 |
def compute_bfi_scores(*args):
|
56 |
responses = list(args)
|
@@ -62,50 +149,6 @@ def compute_bfi_scores(*args):
|
|
62 |
else:
|
63 |
processed.append(int(r))
|
64 |
|
65 |
-
# Define traits with their respective items and scoring parameters
|
66 |
-
traits = {
|
67 |
-
'Extraversion': {
|
68 |
-
'positive': [1, 11, 16, 26, 36],
|
69 |
-
'reverse': [6, 21, 31],
|
70 |
-
'threshold': 1,
|
71 |
-
'formula_pos_mult': 5,
|
72 |
-
'formula_reverse_mult': 3,
|
73 |
-
'formula_reverse_const': 12
|
74 |
-
},
|
75 |
-
'Agreeableness': {
|
76 |
-
'positive': [7, 17, 22, 32, 42],
|
77 |
-
'reverse': [2, 12, 27, 37],
|
78 |
-
'threshold': 1,
|
79 |
-
'formula_pos_mult': 5,
|
80 |
-
'formula_reverse_mult':4,
|
81 |
-
'formula_reverse_const':16
|
82 |
-
},
|
83 |
-
'Conscientiousness': {
|
84 |
-
'positive': [3, 13, 28, 33, 38],
|
85 |
-
'reverse': [8, 18, 23, 43],
|
86 |
-
'threshold': 1,
|
87 |
-
'formula_pos_mult':5,
|
88 |
-
'formula_reverse_mult':4,
|
89 |
-
'formula_reverse_const':16
|
90 |
-
},
|
91 |
-
'Neuroticism':{
|
92 |
-
'positive':[4, 14, 19, 29, 39],
|
93 |
-
'reverse':[9, 24, 34],
|
94 |
-
'threshold':1,
|
95 |
-
'formula_pos_mult':5,
|
96 |
-
'formula_reverse_mult':3,
|
97 |
-
'formula_reverse_const':12
|
98 |
-
},
|
99 |
-
'Openness':{
|
100 |
-
'positive':[5, 10, 15, 20, 25, 30, 40, 44],
|
101 |
-
'reverse':[35, 41],
|
102 |
-
'threshold':2,
|
103 |
-
'formula_pos_mult':8,
|
104 |
-
'formula_reverse_mult':2,
|
105 |
-
'formula_reverse_const':8
|
106 |
-
}
|
107 |
-
}
|
108 |
-
|
109 |
scores = {}
|
110 |
|
111 |
for trait, info in traits.items():
|
@@ -131,30 +174,6 @@ def compute_bfi_scores(*args):
|
|
131 |
score = round(score, 2)
|
132 |
scores[trait] = score
|
133 |
|
134 |
-
# Prepare the output in Markdown format with explanations
|
135 |
-
explanations = {
|
136 |
-
'Extraversion': {
|
137 |
-
'high': "You are highly outgoing, energetic, and enjoy being around people. You thrive in social situations and are often perceived as enthusiastic and lively.",
|
138 |
-
'low': "You are more reserved and prefer solitary activities. You might find large social gatherings draining and enjoy deep, meaningful interactions over casual conversations."
|
139 |
-
},
|
140 |
-
'Agreeableness': {
|
141 |
-
'high': "You are compassionate, cooperative, and value getting along with others. You tend to be trusting and considerate, often putting others' needs before your own.",
|
142 |
-
'low': "You are more competitive and skeptical, prioritizing your own needs and viewpoints. You might be seen as direct or even confrontational in your interactions."
|
143 |
-
},
|
144 |
-
'Conscientiousness': {
|
145 |
-
'high': "You are organized, dependable, and have a strong sense of duty. You strive for achievement and are meticulous in your work, often planning ahead and following through on commitments.",
|
146 |
-
'low': "You are more spontaneous and flexible, potentially preferring to adapt as situations arise rather than sticking to a strict plan. You might find rigid structures stifling."
|
147 |
-
},
|
148 |
-
'Neuroticism':{
|
149 |
-
'high': "You tend to experience emotions like anxiety, sadness, and mood swings more frequently. You might be more sensitive to stress and prone to feeling overwhelmed.",
|
150 |
-
'low': "You are generally calm, resilient, and emotionally stable. You handle stress well and are less likely to experience negative emotions intensely."
|
151 |
-
},
|
152 |
-
'Openness':{
|
153 |
-
'high': "You are imaginative, curious, and open to new experiences. You appreciate art, creativity, and value intellectual exploration and novelty.",
|
154 |
-
'low': "You prefer routine and familiarity, valuing practicality and straightforwardness over abstract ideas. You might be more focused on tangible outcomes rather than theoretical concepts."
|
155 |
-
}
|
156 |
-
}
|
157 |
-
|
158 |
markdown_output = "## Your Big Five Personality Traits Scores\n\n"
|
159 |
|
160 |
# Prepare data for visualization
|
@@ -166,23 +185,15 @@ def compute_bfi_scores(*args):
|
|
166 |
markdown_output += "Insufficient responses to compute this trait.\n\n"
|
167 |
else:
|
168 |
markdown_output += f"**Score**: {score}\n\n"
|
169 |
-
if score
|
|
|
|
|
170 |
markdown_output += f"{explanations[trait]['high']}\n\n"
|
171 |
else:
|
172 |
markdown_output += f"{explanations[trait]['low']}\n\n"
|
173 |
trait_names.append(trait)
|
174 |
trait_scores.append(score)
|
175 |
|
176 |
-
# Function to determine if a score is high or low based on possible range
|
177 |
-
def max_score(trait):
|
178 |
-
# Define maximum possible scores based on formula
|
179 |
-
trait_formula = traits[trait]
|
180 |
-
pos_count = len(trait_formula['positive'])
|
181 |
-
rev_count = len(trait_formula['reverse'])
|
182 |
-
# Maximum score when pos_items are max (5) and rev_items are min (1)
|
183 |
-
max_possible = (5 * trait_formula['formula_pos_mult'] * pos_count / pos_count) + (trait_formula['formula_reverse_const'] - (1 * trait_formula['formula_reverse_mult'] * rev_count / rev_count))
|
184 |
-
return max_possible - (max_possible / 2) # Arbitrary threshold at half the max
|
185 |
-
|
186 |
# Generate bar chart
|
187 |
image = None
|
188 |
if trait_scores:
|
@@ -230,11 +241,11 @@ def create_interface():
|
|
230 |
|
231 |
# Organize questions into expandable sections by trait
|
232 |
trait_question_map = {
|
233 |
-
'Extraversion': [
|
234 |
-
'Agreeableness': [
|
235 |
-
'Conscientiousness': [
|
236 |
-
'Neuroticism': [
|
237 |
-
'Openness': [
|
238 |
}
|
239 |
|
240 |
inputs = []
|
@@ -245,7 +256,7 @@ def create_interface():
|
|
245 |
for i in q_indices:
|
246 |
q = questions[i-1]
|
247 |
# Indicate reverse-scored items
|
248 |
-
if i in traits_reverse_map(trait):
|
249 |
q_display = f"{q} (Reverse Scored)"
|
250 |
else:
|
251 |
q_display = q
|
@@ -274,17 +285,6 @@ def create_interface():
|
|
274 |
|
275 |
return demo
|
276 |
|
277 |
-
# Helper function to determine reverse-scored items for display
|
278 |
-
def traits_reverse_map(trait):
|
279 |
-
traits = {
|
280 |
-
'Extraversion': [6, 21, 31],
|
281 |
-
'Agreeableness': [2, 12, 27, 37],
|
282 |
-
'Conscientiousness': [8, 18, 23, 43],
|
283 |
-
'Neuroticism': [9, 24, 34],
|
284 |
-
'Openness': [35, 41]
|
285 |
-
}
|
286 |
-
return traits.get(trait, [])
|
287 |
-
|
288 |
# Launch the interface
|
289 |
demo = create_interface()
|
290 |
demo.launch()
|
|
|
51 |
"44. Knows a lot about art, music and books"
|
52 |
]
|
53 |
|
54 |
+
# Define reverse-scored items for each trait
|
55 |
+
traits_reverse_map = {
|
56 |
+
'Extraversion': [6, 21, 31],
|
57 |
+
'Agreeableness': [2, 12, 27, 37],
|
58 |
+
'Conscientiousness': [8, 18, 23, 43],
|
59 |
+
'Neuroticism': [9, 24, 34],
|
60 |
+
'Openness': [35, 41]
|
61 |
+
}
|
62 |
+
|
63 |
+
# Define traits with their respective items and scoring parameters
|
64 |
+
traits = {
|
65 |
+
'Extraversion': {
|
66 |
+
'positive': [1, 11, 16, 26, 36],
|
67 |
+
'reverse': [6, 21, 31],
|
68 |
+
'threshold': 1,
|
69 |
+
'formula_pos_mult': 5,
|
70 |
+
'formula_reverse_mult': 3,
|
71 |
+
'formula_reverse_const': 12,
|
72 |
+
'min_score': 2, # Calculated as (1*5) + (12 - (5*3)) = 5 + (12 - 15) = 5 - 3 = 2
|
73 |
+
'max_score': 34 # Calculated as (5*5) + (12 - (1*3)) = 25 + (12 - 3) = 25 + 9 = 34
|
74 |
+
},
|
75 |
+
'Agreeableness': {
|
76 |
+
'positive': [7, 17, 22, 32, 42],
|
77 |
+
'reverse': [2, 12, 27, 37],
|
78 |
+
'threshold': 1,
|
79 |
+
'formula_pos_mult': 5,
|
80 |
+
'formula_reverse_mult':4,
|
81 |
+
'formula_reverse_const':16,
|
82 |
+
'min_score': 5, # (1*5) + (16 - (5*4)) = 5 + (16 - 20) = 5 - 4 = 1
|
83 |
+
'max_score': 41 # (5*5) + (16 - (1*4)) = 25 + (16 - 4) = 25 + 12 = 37
|
84 |
+
},
|
85 |
+
'Conscientiousness': {
|
86 |
+
'positive': [3, 13, 28, 33, 38],
|
87 |
+
'reverse': [8, 18, 23, 43],
|
88 |
+
'threshold': 1,
|
89 |
+
'formula_pos_mult':5,
|
90 |
+
'formula_reverse_mult':4,
|
91 |
+
'formula_reverse_const':16,
|
92 |
+
'min_score': 1, # (1*5) + (16 - (5*4)) = 5 + (16 - 20) = 5 -4 =1
|
93 |
+
'max_score': 37 # (5*5) + (16 - (1*4)) =25 + (16-4)=25+12=37
|
94 |
+
},
|
95 |
+
'Neuroticism':{
|
96 |
+
'positive':[4, 14, 19, 29, 39],
|
97 |
+
'reverse':[9, 24, 34],
|
98 |
+
'threshold':1,
|
99 |
+
'formula_pos_mult':5,
|
100 |
+
'formula_reverse_mult':3,
|
101 |
+
'formula_reverse_const':12,
|
102 |
+
'min_score':2, # (1*5) + (12 - (5*3)) =5 + (12-15)=5-3=2
|
103 |
+
'max_score':32 # (5*5) + (12 - (1*3))=25 + (12-3)=25+9=34
|
104 |
+
},
|
105 |
+
'Openness':{
|
106 |
+
'positive':[5, 10, 15, 20, 25, 30, 40, 44],
|
107 |
+
'reverse':[35, 41],
|
108 |
+
'threshold':2,
|
109 |
+
'formula_pos_mult':8,
|
110 |
+
'formula_reverse_mult':2,
|
111 |
+
'formula_reverse_const':8,
|
112 |
+
'min_score':8, # (1*8) + (8 - (5*2)) =8 + (8-10)=8-2=6
|
113 |
+
'max_score':48 # (5*8) + (8 - (1*2))=40 + (8-2)=40+6=46
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
# Define explanations for each trait based on high or low scores
|
118 |
+
explanations = {
|
119 |
+
'Extraversion': {
|
120 |
+
'high': "You are highly outgoing, energetic, and enjoy being around people. You thrive in social situations and are often perceived as enthusiastic and lively.",
|
121 |
+
'low': "You are more reserved and prefer solitary activities. You might find large social gatherings draining and enjoy deep, meaningful interactions over casual conversations."
|
122 |
+
},
|
123 |
+
'Agreeableness': {
|
124 |
+
'high': "You are compassionate, cooperative, and value getting along with others. You tend to be trusting and considerate, often putting others' needs before your own.",
|
125 |
+
'low': "You are more competitive and skeptical, prioritizing your own needs and viewpoints. You might be seen as direct or even confrontational in your interactions."
|
126 |
+
},
|
127 |
+
'Conscientiousness': {
|
128 |
+
'high': "You are organized, dependable, and have a strong sense of duty. You strive for achievement and are meticulous in your work, often planning ahead and following through on commitments.",
|
129 |
+
'low': "You are more spontaneous and flexible, potentially preferring to adapt as situations arise rather than sticking to a strict plan. You might find rigid structures stifling."
|
130 |
+
},
|
131 |
+
'Neuroticism':{
|
132 |
+
'high': "You tend to experience emotions like anxiety, sadness, and mood swings more frequently. You might be more sensitive to stress and prone to feeling overwhelmed.",
|
133 |
+
'low': "You are generally calm, resilient, and emotionally stable. You handle stress well and are less likely to experience negative emotions intensely."
|
134 |
+
},
|
135 |
+
'Openness':{
|
136 |
+
'high': "You are imaginative, curious, and open to new experiences. You appreciate art, creativity, and value intellectual exploration and novelty.",
|
137 |
+
'low': "You prefer routine and familiarity, valuing practicality and straightforwardness over abstract ideas. You might be more focused on tangible outcomes rather than theoretical concepts."
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
# Scoring function based on the provided SPSS syntax
|
142 |
def compute_bfi_scores(*args):
|
143 |
responses = list(args)
|
|
|
149 |
else:
|
150 |
processed.append(int(r))
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
scores = {}
|
153 |
|
154 |
for trait, info in traits.items():
|
|
|
174 |
score = round(score, 2)
|
175 |
scores[trait] = score
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
markdown_output = "## Your Big Five Personality Traits Scores\n\n"
|
178 |
|
179 |
# Prepare data for visualization
|
|
|
185 |
markdown_output += "Insufficient responses to compute this trait.\n\n"
|
186 |
else:
|
187 |
markdown_output += f"**Score**: {score}\n\n"
|
188 |
+
# Determine if the score is high or low based on midpoint
|
189 |
+
midpoint = (traits[trait]['min_score'] + traits[trait]['max_score']) / 2
|
190 |
+
if score >= midpoint:
|
191 |
markdown_output += f"{explanations[trait]['high']}\n\n"
|
192 |
else:
|
193 |
markdown_output += f"{explanations[trait]['low']}\n\n"
|
194 |
trait_names.append(trait)
|
195 |
trait_scores.append(score)
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
# Generate bar chart
|
198 |
image = None
|
199 |
if trait_scores:
|
|
|
241 |
|
242 |
# Organize questions into expandable sections by trait
|
243 |
trait_question_map = {
|
244 |
+
'Extraversion': traits['Extraversion']['positive'] + traits['Extraversion']['reverse'],
|
245 |
+
'Agreeableness': traits['Agreeableness']['positive'] + traits['Agreeableness']['reverse'],
|
246 |
+
'Conscientiousness': traits['Conscientiousness']['positive'] + traits['Conscientiousness']['reverse'],
|
247 |
+
'Neuroticism': traits['Neuroticism']['positive'] + traits['Neuroticism']['reverse'],
|
248 |
+
'Openness': traits['Openness']['positive'] + traits['Openness']['reverse']
|
249 |
}
|
250 |
|
251 |
inputs = []
|
|
|
256 |
for i in q_indices:
|
257 |
q = questions[i-1]
|
258 |
# Indicate reverse-scored items
|
259 |
+
if i in traits_reverse_map.get(trait, []):
|
260 |
q_display = f"{q} (Reverse Scored)"
|
261 |
else:
|
262 |
q_display = q
|
|
|
285 |
|
286 |
return demo
|
287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
# Launch the interface
|
289 |
demo = create_interface()
|
290 |
demo.launch()
|