johnpaulbin commited on
Commit
b070298
·
verified ·
1 Parent(s): 3ea6e87

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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
52
+ traits = {
53
+ 'Extraversion': {
54
+ 'positive': ['BFI_1', 'BFI_11', 'BFI_16', 'BFI_26', 'BFI_36'],
55
+ 'negative': ['BFI_6', 'BFI_21', 'BFI_31'],
56
+ },
57
+ 'Agreeableness': {
58
+ 'positive': ['BFI_7', 'BFI_17', 'BFI_22', 'BFI_32', 'BFI_42'],
59
+ 'negative': ['BFI_2', 'BFI_12', 'BFI_27', 'BFI_37'],
60
+ },
61
+ 'Conscientiousness': {
62
+ 'positive': ['BFI_3', 'BFI_13', 'BFI_28', 'BFI_33', 'BFI_38'],
63
+ 'negative': ['BFI_8', 'BFI_18', 'BFI_23', 'BFI_43'],
64
+ },
65
+ 'Neuroticism': {
66
+ 'positive': ['BFI_4', 'BFI_14', 'BFI_19', 'BFI_29', 'BFI_39'],
67
+ 'negative': ['BFI_9', 'BFI_24', 'BFI_34'],
68
+ },
69
+ 'Openness': {
70
+ 'positive': ['BFI_5', 'BFI_10', 'BFI_15', 'BFI_20', 'BFI_25', 'BFI_30', 'BFI_40', 'BFI_44'],
71
+ 'negative': ['BFI_35', 'BFI_41'],
72
+ }
73
+ }
74
+
75
+ # Define the scoring function
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
+
93
+ return trait_scores
94
+
95
+ # Create the Gradio interface
96
+ inputs = []
97
+ for item in items:
98
+ question = item['question']
99
+ input_component = gr.Radio(
100
+ label=question,
101
+ choices=['1 (Disagree a lot)', '2', '3', '4', '5 (Agree a lot)'],
102
+ type='value',
103
+ required=True
104
+ )
105
+ inputs.append(input_component)
106
+
107
+ iface = gr.Interface(
108
+ fn=compute_trait_scores,
109
+ inputs=inputs,
110
+ outputs=gr.JSON(label="Your Big Five Personality Scores"),
111
+ title='Big Five Personality Test',
112
+ description='Answer the following questions to see your Big Five personality trait scores.',
113
+ allow_flagging='never'
114
+ )
115
+
116
+ iface.launch()