johnpaulbin commited on
Commit
2a34d99
·
verified ·
1 Parent(s): 5180790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -52
app.py CHANGED
@@ -2,50 +2,50 @@ import gradio as gr
2
 
3
  # Define the list of items with their questions and whether they are reverse-scored
4
  items = [
5
- {'BFI': 'BFI_1', 'question': 'Talks a lot', 'reverse': False},
6
- {'BFI': 'BFI_2', 'question': 'Notices other people’s weak points', 'reverse': True},
7
- {'BFI': 'BFI_3', 'question': 'Does things carefully and completely', 'reverse': False},
8
- {'BFI': 'BFI_4', 'question': 'Is sad, depressed', 'reverse': False},
9
- {'BFI': 'BFI_5', 'question': 'Is original, comes up with new ideas', 'reverse': False},
10
- {'BFI': 'BFI_6', 'question': 'Keeps their thoughts to themselves', 'reverse': True},
11
- {'BFI': 'BFI_7', 'question': 'Is helpful and not selfish with others', 'reverse': False},
12
- {'BFI': 'BFI_8', 'question': 'Can be kind of careless', 'reverse': True},
13
- {'BFI': 'BFI_9', 'question': 'Is relaxed, handles stress well', 'reverse': True},
14
- {'BFI': 'BFI_10', 'question': 'Is curious about lots of different things', 'reverse': False},
15
- {'BFI': 'BFI_11', 'question': 'Has a lot of energy', 'reverse': False},
16
- {'BFI_12': 'question': 'Starts arguments with others', 'reverse': True},
17
- {'BFI_13': 'question': 'Is a good, hard worker', 'reverse': False},
18
- {'BFI_14': 'question': 'Can be tense; not always easy going', 'reverse': False},
19
- {'BFI_15': 'question': 'Clever; thinks a lot', 'reverse': False},
20
- {'BFI_16': 'question': 'Makes things exciting', 'reverse': False},
21
- {'BFI_17': 'question': 'Forgives others easily', 'reverse': False},
22
- {'BFI_18': 'question': 'Isn\'t very organized', 'reverse': True},
23
- {'BFI_19': 'question': 'Worries a lot', 'reverse': False},
24
- {'BFI_20': 'question': 'Has a good, active imagination', 'reverse': False},
25
- {'BFI_21': 'question': 'Tends to be quiet', 'reverse': True},
26
- {'BFI_22': 'question': 'Usually trusts people', 'reverse': False},
27
- {'BFI_23': 'question': 'Tends to be lazy', 'reverse': True},
28
- {'BFI_24': 'question': 'Doesn\'t get upset easily; steady', 'reverse': True},
29
- {'BFI_25': 'question': 'Is creative and inventive', 'reverse': False},
30
- {'BFI_26': 'question': 'Has a good, strong personality', 'reverse': False},
31
- {'BFI_27': 'question': 'Can be cold and distant with others', 'reverse': True},
32
- {'BFI_28': 'question': 'Keeps working until things are done', 'reverse': False},
33
- {'BFI_29': 'question': 'Can be moody', 'reverse': False},
34
- {'BFI_30': 'question': 'Likes artistic and creative experiences', 'reverse': False},
35
- {'BFI_31': 'question': 'Is kind of shy', 'reverse': True},
36
- {'BFI_32': 'question': 'Kind and considerate to almost everyone', 'reverse': False},
37
- {'BFI_33': 'question': 'Does things quickly and carefully', 'reverse': False},
38
- {'BFI_34': 'question': 'Stays calm in difficult situations', 'reverse': True},
39
- {'BFI_35': 'question': 'Likes work that is the same every time', 'reverse': True},
40
- {'BFI_36': 'question': 'Is outgoing; likes to be with people', 'reverse': False},
41
- {'BFI_37': 'question': 'Is sometimes rude to others', 'reverse': True},
42
- {'BFI_38': 'question': 'Makes plans and sticks to them', 'reverse': False},
43
- {'BFI_39': 'question': 'Gets nervous easily', 'reverse': False},
44
- {'BFI_40': 'question': 'Likes to think and play with ideas', 'reverse': False},
45
- {'BFI_41': 'question': 'Doesn\'t like artistic things (plays, music)', 'reverse': True},
46
- {'BFI_42': 'question': 'Likes to cooperate; goes along with others', 'reverse': False},
47
- {'BFI_43': 'question': 'Has trouble paying attention', 'reverse': True},
48
- {'BFI_44': 'question': 'Knows a lot about art, music, and books', 'reverse': False},
49
  ]
50
 
51
  # Define which items belong to which traits
@@ -76,17 +76,24 @@ traits = {
76
  def compute_trait_scores(*args):
77
  responses = {}
78
  for i, item in enumerate(items):
79
- BFI = item['BFI']
80
  response = int(args[i])
81
- responses[BFI] = response
82
 
83
  trait_scores = {}
84
- for trait in traits:
85
- positive_items = traits[trait]['positive']
86
- negative_items = traits[trait]['negative']
87
-
88
- positive_sum = sum(responses[item] for item in positive_items)
89
- negative_sum = sum(6 - responses[item] for item in negative_items)
 
 
 
 
 
 
 
90
 
91
  trait_scores[trait] = positive_sum + negative_sum
92
 
 
2
 
3
  # Define the list of items with their questions and whether they are reverse-scored
4
  items = [
5
+ {'key': 'BFI_1', 'question': 'Talks a lot', 'reverse': False},
6
+ {'key': 'BFI_2', 'question': 'Notices other people’s weak points', 'reverse': True},
7
+ {'key': 'BFI_3', 'question': 'Does things carefully and completely', 'reverse': False},
8
+ {'key': 'BFI_4', 'question': 'Is sad, depressed', 'reverse': False},
9
+ {'key': 'BFI_5', 'question': 'Is original, comes up with new ideas', 'reverse': False},
10
+ {'key': 'BFI_6', 'question': 'Keeps their thoughts to themselves', 'reverse': True},
11
+ {'key': 'BFI_7', 'question': 'Is helpful and not selfish with others', 'reverse': False},
12
+ {'key': 'BFI_8', 'question': 'Can be kind of careless', 'reverse': True},
13
+ {'key': 'BFI_9', 'question': 'Is relaxed, handles stress well', 'reverse': True},
14
+ {'key': 'BFI_10', 'question': 'Is curious about lots of different things', 'reverse': False},
15
+ {'key': 'BFI_11', 'question': 'Has a lot of energy', 'reverse': False},
16
+ {'key': 'BFI_12', 'question': 'Starts arguments with others', 'reverse': True},
17
+ {'key': 'BFI_13', 'question': 'Is a good, hard worker', 'reverse': False},
18
+ {'key': 'BFI_14', 'question': 'Can be tense; not always easy going', 'reverse': False},
19
+ {'key': 'BFI_15', 'question': 'Clever; thinks a lot', 'reverse': False},
20
+ {'key': 'BFI_16', 'question': 'Makes things exciting', 'reverse': False},
21
+ {'key': 'BFI_17', 'question': 'Forgives others easily', 'reverse': False},
22
+ {'key': 'BFI_18', 'question': 'Isn\'t very organized', 'reverse': True},
23
+ {'key': 'BFI_19', 'question': 'Worries a lot', 'reverse': False},
24
+ {'key': 'BFI_20', 'question': 'Has a good, active imagination', 'reverse': False},
25
+ {'key': 'BFI_21', 'question': 'Tends to be quiet', 'reverse': True},
26
+ {'key': 'BFI_22', 'question': 'Usually trusts people', 'reverse': False},
27
+ {'key': 'BFI_23', 'question': 'Tends to be lazy', 'reverse': True},
28
+ {'key': 'BFI_24', 'question': 'Doesn\'t get upset easily; steady', 'reverse': True},
29
+ {'key': 'BFI_25', 'question': 'Is creative and inventive', 'reverse': False},
30
+ {'key': 'BFI_26', 'question': 'Has a good, strong personality', 'reverse': False},
31
+ {'key': 'BFI_27', 'question': 'Can be cold and distant with others', 'reverse': True},
32
+ {'key': 'BFI_28', 'question': 'Keeps working until things are done', 'reverse': False},
33
+ {'key': 'BFI_29', 'question': 'Can be moody', 'reverse': False},
34
+ {'key': 'BFI_30', 'question': 'Likes artistic and creative experiences', 'reverse': False},
35
+ {'key': 'BFI_31', 'question': 'Is kind of shy', 'reverse': True},
36
+ {'key': 'BFI_32', 'question': 'Kind and considerate to almost everyone', 'reverse': False},
37
+ {'key': 'BFI_33', 'question': 'Does things quickly and carefully', 'reverse': False},
38
+ {'key': 'BFI_34', 'question': 'Stays calm in difficult situations', 'reverse': True},
39
+ {'key': 'BFI_35', 'question': 'Likes work that is the same every time', 'reverse': True},
40
+ {'key': 'BFI_36', 'question': 'Is outgoing; likes to be with people', 'reverse': False},
41
+ {'key': 'BFI_37', 'question': 'Is sometimes rude to others', 'reverse': True},
42
+ {'key': 'BFI_38', 'question': 'Makes plans and sticks to them', 'reverse': False},
43
+ {'key': 'BFI_39', 'question': 'Gets nervous easily', 'reverse': False},
44
+ {'key': 'BFI_40', 'question': 'Likes to think and play with ideas', 'reverse': False},
45
+ {'key': 'BFI_41', 'question': 'Doesn\'t like artistic things (plays, music)', 'reverse': True},
46
+ {'key': 'BFI_42', 'question': 'Likes to cooperate; goes along with others', 'reverse': False},
47
+ {'key': 'BFI_43', 'question': 'Has trouble paying attention', 'reverse': True},
48
+ {'key': 'BFI_44', 'question': 'Knows a lot about art, music, and books', 'reverse': False},
49
  ]
50
 
51
  # Define which items belong to which traits
 
76
  def compute_trait_scores(*args):
77
  responses = {}
78
  for i, item in enumerate(items):
79
+ key = item['key']
80
  response = int(args[i])
81
+ responses[key] = response
82
 
83
  trait_scores = {}
84
+ for trait, trait_data in traits.items():
85
+ positive_sum = 0
86
+ negative_sum = 0
87
+ for item_key in trait_data['positive']:
88
+ try:
89
+ positive_sum += responses[item_key]
90
+ except KeyError:
91
+ print(f"Warning: Response for {item_key} not found.") #Handle missing keys gracefully.
92
+ for item_key in trait_data['negative']:
93
+ try:
94
+ negative_sum += 6 - responses[item_key]
95
+ except KeyError:
96
+ print(f"Warning: Response for {item_key} not found.") #Handle missing keys gracefully.
97
 
98
  trait_scores[trait] = positive_sum + negative_sum
99