Update app.py
Browse files
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 |
-
{'
|
6 |
-
{'
|
7 |
-
{'
|
8 |
-
{'
|
9 |
-
{'
|
10 |
-
{'
|
11 |
-
{'
|
12 |
-
{'
|
13 |
-
{'
|
14 |
-
{'
|
15 |
-
{'
|
16 |
-
{'
|
17 |
-
{'
|
18 |
-
{'
|
19 |
-
{'
|
20 |
-
{'
|
21 |
-
{'
|
22 |
-
{'
|
23 |
-
{'
|
24 |
-
{'
|
25 |
-
{'
|
26 |
-
{'
|
27 |
-
{'
|
28 |
-
{'
|
29 |
-
{'
|
30 |
-
{'
|
31 |
-
{'
|
32 |
-
{'
|
33 |
-
{'
|
34 |
-
{'
|
35 |
-
{'
|
36 |
-
{'
|
37 |
-
{'
|
38 |
-
{'
|
39 |
-
{'
|
40 |
-
{'
|
41 |
-
{'
|
42 |
-
{'
|
43 |
-
{'
|
44 |
-
{'
|
45 |
-
{'
|
46 |
-
{'
|
47 |
-
{'
|
48 |
-
{'
|
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 |
-
|
80 |
response = int(args[i])
|
81 |
-
responses[
|
82 |
|
83 |
trait_scores = {}
|
84 |
-
for trait in traits:
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|