File size: 5,930 Bytes
b070298
 
 
 
39756f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b070298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39756f7
b070298
 
 
39756f7
 
 
b070298
 
39756f7
 
 
 
 
 
b070298
 
 
 
 
 
 
 
 
 
 
 
39756f7
 
b070298
 
 
39756f7
 
 
 
 
 
 
 
 
 
1
2
3
4
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import gradio as gr

# Define the list of items with their questions and whether they are reverse-scored
items = [
    {'BFI': 'BFI_1', 'question': 'Talks a lot', 'reverse': False},
    {'BFI': 'BFI_2', 'question': 'Notices other people's weak points', 'reverse': True},
    {'BFI': 'BFI_3', 'question': 'Does things carefully and completely', 'reverse': False},
    {'BFI': 'BFI_4', 'question': 'Is sad, depressed', 'reverse': False},
    {'BFI': 'BFI_5', 'question': 'Is original, comes up with new ideas', 'reverse': False},
    {'BFI': 'BFI_6', 'question': 'Keeps their thoughts to themselves', 'reverse': True},
    {'BFI': 'BFI_7', 'question': 'Is helpful and not selfish with others', 'reverse': False},
    {'BFI': 'BFI_8', 'question': 'Can be kind of careless', 'reverse': True},
    {'BFI': 'BFI_9', 'question': 'Is relaxed, handles stress well', 'reverse': True},
    {'BFI': 'BFI_10', 'question': 'Is curious about lots of different things', 'reverse': False},
    {'BFI': 'BFI_11', 'question': 'Has a lot of energy', 'reverse': False},
    {'BFI': 'BFI_12', 'question': 'Starts arguments with others', 'reverse': True},
    {'BFI': 'BFI_13', 'question': 'Is a good, hard worker', 'reverse': False},
    {'BFI': 'BFI_14', 'question': 'Can be tense; not always easy going', 'reverse': False},
    {'BFI': 'BFI_15', 'question': 'Clever; thinks a lot', 'reverse': False},
    {'BFI': 'BFI_16', 'question': 'Makes things exciting', 'reverse': False},
    {'BFI': 'BFI_17', 'question': 'Forgives others easily', 'reverse': False},
    {'BFI': 'BFI_18', 'question': 'Isn\'t very organized', 'reverse': True},
    {'BFI': 'BFI_19', 'question': 'Worries a lot', 'reverse': False},
    {'BFI': 'BFI_20', 'question': 'Has a good, active imagination', 'reverse': False},
    {'BFI': 'BFI_21', 'question': 'Tends to be quiet', 'reverse': True},
    {'BFI': 'BFI_22', 'question': 'Usually trusts people', 'reverse': False},
    {'BFI': 'BFI_23', 'question': 'Tends to be lazy', 'reverse': True},
    {'BFI': 'BFI_24', 'question': 'Doesn\'t get upset easily; steady', 'reverse': True},
    {'BFI': 'BFI_25', 'question': 'Is creative and inventive', 'reverse': False},
    {'BFI': 'BFI_26', 'question': 'Has a good, strong personality', 'reverse': False},
    {'BFI': 'BFI_27', 'question': 'Can be cold and distant with others', 'reverse': True},
    {'BFI': 'BFI_28', 'question': 'Keeps working until things are done', 'reverse': False},
    {'BFI': 'BFI_29', 'question': 'Can be moody', 'reverse': False},
    {'BFI': 'BFI_30', 'question': 'Likes artistic and creative experiences', 'reverse': False},
    {'BFI': 'BFI_31', 'question': 'Is kind of shy', 'reverse': True},
    {'BFI': 'BFI_32', 'question': 'Kind and considerate to almost everyone', 'reverse': False},
    {'BFI': 'BFI_33', 'question': 'Does things quickly and carefully', 'reverse': False},
    {'BFI': 'BFI_34', 'question': 'Stays calm in difficult situations', 'reverse': True},
    {'BFI': 'BFI_35', 'question': 'Likes work that is the same every time', 'reverse': True},
    {'BFI': 'BFI_36', 'question': 'Is outgoing; likes to be with people', 'reverse': False},
    {'BFI': 'BFI_37', 'question': 'Is sometimes rude to others', 'reverse': True},
    {'BFI': 'BFI_38', 'question': 'Makes plans and sticks to them', 'reverse': False},
    {'BFI': 'BFI_39', 'question': 'Gets nervous easily', 'reverse': False},
    {'BFI': 'BFI_40', 'question': 'Likes to think and play with ideas', 'reverse': False},
    {'BFI': 'BFI_41', 'question': 'Doesn\'t like artistic things (plays, music)', 'reverse': True},
    {'BFI': 'BFI_42', 'question': 'Likes to cooperate; goes along with others', 'reverse': False},
    {'BFI': 'BFI_43', 'question': 'Has trouble paying attention', 'reverse': True},
    {'BFI': 'BFI_44', 'question': 'Knows a lot about art, music, and books', 'reverse': False},
]

# Define which items belong to which traits
traits = {
    'Extraversion': {
        'positive': ['BFI_1', 'BFI_11', 'BFI_16', 'BFI_26', 'BFI_36'],
        'negative': ['BFI_6', 'BFI_21', 'BFI_31'],
    },
    'Agreeableness': {
        'positive': ['BFI_7', 'BFI_17', 'BFI_22', 'BFI_32', 'BFI_42'],
        'negative': ['BFI_2', 'BFI_12', 'BFI_27', 'BFI_37'],
    },
    'Conscientiousness': {
        'positive': ['BFI_3', 'BFI_13', 'BFI_28', 'BFI_33', 'BFI_38'],
        'negative': ['BFI_8', 'BFI_18', 'BFI_23', 'BFI_43'],
    },
    'Neuroticism': {
        'positive': ['BFI_4', 'BFI_14', 'BFI_19', 'BFI_29', 'BFI_39'],
        'negative': ['BFI_9', 'BFI_24', 'BFI_34'],
    },
    'Openness': {
        'positive': ['BFI_5', 'BFI_10', 'BFI_15', 'BFI_20', 'BFI_25', 'BFI_30', 'BFI_40', 'BFI_44'],
        'negative': ['BFI_35', 'BFI_41'],
    }
}

# Define the scoring function
def compute_trait_scores(*args):
    responses = {}
    for i, item in enumerate(items):
        BFI = item['BFI']
        response = int(args[i])
        responses[BFI] = response

    trait_scores = {}
    for trait in traits:
        positive_items = traits[trait]['positive']
        negative_items = traits[trait]['negative']

        positive_sum = sum(responses[item] for item in positive_items)
        negative_sum = sum(6 - responses[item] for item in negative_items)

        trait_scores[trait] = positive_sum + negative_sum

    return trait_scores

# Create the Gradio interface
inputs = []
for item in items:
    question = item['question']
    input_component = gr.Radio(
        label=question,
        choices=['1 (Disagree a lot)', '2', '3', '4', '5 (Agree a lot)'],
        type='value',
        required=True
    )
    inputs.append(input_component)

iface = gr.Interface(
    fn=compute_trait_scores,
    inputs=inputs,
    outputs=gr.outputs.JSON(label="Your Big Five Personality Scores"),
    title='Big Five Personality Test',
    description='Answer the following questions to see your Big Five personality trait scores.',
    allow_flagging='never'
)

iface.launch()