johnpaulbin commited on
Commit
184bf40
·
verified ·
1 Parent(s): d413ee5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -15
app.py CHANGED
@@ -43,7 +43,7 @@ questions = [
43
  "36. Is outgoing; likes to be with people",
44
  "37. Is sometimes rude to others",
45
  "38. Makes plans and sticks to them",
46
- "39. Get nervous easily",
47
  "40. Likes to think and play with ideas",
48
  "41. Doesn’t like artistic things (plays, music)",
49
  "42. Likes to cooperate; goes along with others",
@@ -133,11 +133,26 @@ def compute_bfi_scores(*args):
133
 
134
  # Prepare the output in Markdown format with explanations
135
  explanations = {
136
- 'Extraversion': "Extraversion reflects how outgoing and energetic you are. High scores indicate sociability and enthusiasm, while low scores suggest a more reserved and solitary nature.",
137
- 'Agreeableness': "Agreeableness measures your tendency to be compassionate and cooperative. High scores signify kindness and trust, whereas low scores may indicate competitiveness or skepticism.",
138
- 'Conscientiousness': "Conscientiousness assesses your level of self-discipline and organization. High scores denote reliability and thoroughness, while low scores might reflect a more spontaneous or disorganized approach.",
139
- 'Neuroticism': "Neuroticism indicates emotional stability and susceptibility to stress. High scores suggest a tendency towards anxiety and moodiness, whereas low scores imply calmness and resilience.",
140
- 'Openness': "Openness measures your openness to new experiences and creativity. High scores are associated with imagination and curiosity, while low scores may indicate practicality and preference for routine."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
  markdown_output = "## Your Big Five Personality Traits Scores\n\n"
@@ -151,14 +166,27 @@ def compute_bfi_scores(*args):
151
  markdown_output += "Insufficient responses to compute this trait.\n\n"
152
  else:
153
  markdown_output += f"**Score**: {score}\n\n"
154
- markdown_output += f"{explanations[trait]}\n\n"
 
 
 
155
  trait_names.append(trait)
156
  trait_scores.append(score)
157
 
 
 
 
 
 
 
 
 
 
 
158
  # Generate bar chart
159
  image = None
160
  if trait_scores:
161
- fig, ax = plt.subplots(figsize=(8, 4))
162
  bars = ax.bar(trait_names, trait_scores, color='skyblue')
163
  ax.set_ylim(0, max(trait_scores) + 10)
164
  ax.set_ylabel('Score')
@@ -202,23 +230,28 @@ def create_interface():
202
 
203
  # Organize questions into expandable sections by trait
204
  trait_question_map = {
205
- 'Extraversion': [1, 6, 11, 16, 21, 26, 31, 36],
206
- 'Agreeableness': [2, 7, 12, 17, 22, 27, 32, 37, 42],
207
- 'Conscientiousness': [3, 8, 13, 18, 23, 28, 33, 38, 43],
208
- 'Neuroticism': [4, 9, 14, 19, 24, 29, 34, 39],
209
- 'Openness': [5, 10, 15, 20, 25, 30, 35, 40, 41, 44]
210
  }
211
 
212
  inputs = []
213
 
214
  with gr.Accordion("Answer the Questions", open=True):
215
  for trait, q_indices in trait_question_map.items():
216
- with gr.Accordion(trait, open=False):
217
  for i in q_indices:
218
  q = questions[i-1]
 
 
 
 
 
219
  radio = gr.Radio(
220
  choices=["No response", 1, 2, 3, 4, 5],
221
- label=q,
222
  value="No response",
223
  interactive=True
224
  )
@@ -241,6 +274,17 @@ def create_interface():
241
 
242
  return demo
243
 
 
 
 
 
 
 
 
 
 
 
 
244
  # Launch the interface
245
  demo = create_interface()
246
  demo.launch()
 
43
  "36. Is outgoing; likes to be with people",
44
  "37. Is sometimes rude to others",
45
  "38. Makes plans and sticks to them",
46
+ "39. Gets nervous easily",
47
  "40. Likes to think and play with ideas",
48
  "41. Doesn’t like artistic things (plays, music)",
49
  "42. Likes to cooperate; goes along with others",
 
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"
 
166
  markdown_output += "Insufficient responses to compute this trait.\n\n"
167
  else:
168
  markdown_output += f"**Score**: {score}\n\n"
169
+ if score >= (max_score(trait)):
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:
189
+ fig, ax = plt.subplots(figsize=(10, 6))
190
  bars = ax.bar(trait_names, trait_scores, color='skyblue')
191
  ax.set_ylim(0, max(trait_scores) + 10)
192
  ax.set_ylabel('Score')
 
230
 
231
  # Organize questions into expandable sections by trait
232
  trait_question_map = {
233
+ 'Extraversion': [1, 11, 16, 26, 36, 6, 21, 31], # Positive followed by reverse
234
+ 'Agreeableness': [7, 17, 22, 32, 42, 2, 12, 27, 37],
235
+ 'Conscientiousness': [3, 13, 28, 33, 38, 8, 18, 23, 43],
236
+ 'Neuroticism': [4, 14, 19, 29, 39, 9, 24, 34],
237
+ 'Openness': [5, 10, 15, 20, 25, 30, 40, 44, 35, 41]
238
  }
239
 
240
  inputs = []
241
 
242
  with gr.Accordion("Answer the Questions", open=True):
243
  for trait, q_indices in trait_question_map.items():
244
+ with gr.Accordion(f"{trait}", open=False):
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
252
  radio = gr.Radio(
253
  choices=["No response", 1, 2, 3, 4, 5],
254
+ label=q_display,
255
  value="No response",
256
  interactive=True
257
  )
 
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()