Spaces:
Runtime error
Runtime error
Michelangiolo
commited on
Commit
•
56fcd5f
1
Parent(s):
ecb22b1
first push
Browse files- Big5.csv +50 -0
- app.py +75 -0
- big5_gradio.ipynb +167 -0
Big5.csv
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Am the life of the party.;;;;;;(1+)
|
2 |
+
Feel little concern for others.;;;;;;(2-)
|
3 |
+
Am always prepared.;;;;;;(3+)
|
4 |
+
Get stressed out easily.;;;;;;(4-)
|
5 |
+
Have a rich vocabulary.;;;;;;(5+)
|
6 |
+
Don't talk a lot.;;;;;;(1-)
|
7 |
+
Am interested in people.;;;;;;(2+)
|
8 |
+
Leave my belongings around.;;;;;;(3-)
|
9 |
+
Am relaxed most of the time.;;;;;;(4+)
|
10 |
+
Have difficulty understanding abstract ideas.;;;;;;(5-)
|
11 |
+
Feel comfortable around people.;;;;;;(1+)
|
12 |
+
Insult people.;;;;;;(2-)
|
13 |
+
Pay attention to details.;;;;;;(3+)
|
14 |
+
Worry about things.;;;;;;(4-)
|
15 |
+
Have a vivid imagination.;;;;;;(5+)
|
16 |
+
Keep in the background.;;;;;;(1-)
|
17 |
+
Sympathize with others' feelings.;;;;;;(2+)
|
18 |
+
Make a mess of things.;;;;;;(3-)
|
19 |
+
Seldom feel blue.;;;;;;(4+)
|
20 |
+
Am not interested in abstract ideas.;;;;;;(5-)
|
21 |
+
Start conversations.;;;;;;(1+)
|
22 |
+
Am not interested in other people's problems.;;;;;;(2-)
|
23 |
+
Get chores done right away.;;;;;;(3+)
|
24 |
+
Am easily disturbed.;;;;;;(4-)
|
25 |
+
Have excellent ideas.;;;;;;(5+)
|
26 |
+
Have little to say.;;;;;;(1-)
|
27 |
+
Have a soft heart.;;;;;;(2+)
|
28 |
+
Often forget to put things back in their proper place.;;;;;;(3-)
|
29 |
+
Get upset easily.;;;;;;(4-)
|
30 |
+
Do not have a good imagination.;;;;;;(5-)
|
31 |
+
Talk to a lot of different people at parties.;;;;;;(1+)
|
32 |
+
Am not really interested in others.;;;;;;(2-)
|
33 |
+
Like order.;;;;;;(3+)
|
34 |
+
Change my mood a lot.;;;;;;(4-)
|
35 |
+
Am quick to understand things.;;;;;;(5+)
|
36 |
+
Don't like to draw attention to myself.;;;;;;(1-)
|
37 |
+
Take time out for others.;;;;;;(2+)
|
38 |
+
Shirk my duties.;;;;;;(3-)
|
39 |
+
Have frequent mood swings.;;;;;;(4-)
|
40 |
+
Use difficult words.;;;;;;(5+)
|
41 |
+
Don't mind being the center of attention.;;;;;;(1+)
|
42 |
+
Feel others' emotions.;;;;;;(2+)
|
43 |
+
Follow a schedule.;;;;;;(3+)
|
44 |
+
Get irritated easily.;;;;;;(4-)
|
45 |
+
Spend time reflecting on things.;;;;;;(5+)
|
46 |
+
Am quiet around strangers.;;;;;;(1-)
|
47 |
+
Make people feel at ease.;;;;;;(2+)
|
48 |
+
Am exacting in my work.;;;;;;(3+)
|
49 |
+
Often feel blue.;;;;;;(4-)
|
50 |
+
Am full of ideas.;;;;;;(5+)
|
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#os.system('pip install openpyxl') #works for huggingface-spaces
|
2 |
+
#score of each latent variable ranges in [10, 50]
|
3 |
+
def correct_score(score, big_5_indicator):
|
4 |
+
big_5_sign = big_5_indicator[0]
|
5 |
+
big_5_num = int(big_5_indicator[1])
|
6 |
+
dict1 = {
|
7 |
+
1 : 'Extraversion',
|
8 |
+
2 : 'Agreeableness',
|
9 |
+
3 : 'Conscientiousness',
|
10 |
+
4 : 'Neuroticism',
|
11 |
+
5 : 'Openness'
|
12 |
+
}
|
13 |
+
if big_5_sign=='+':
|
14 |
+
return [dict1[big_5_num], score]
|
15 |
+
elif big_5_sign =='-':
|
16 |
+
return [dict1[big_5_num], 6-score]
|
17 |
+
# correct_score(3, big_5_indicator='-2')
|
18 |
+
|
19 |
+
def make_question(q):
|
20 |
+
q = gr.Radio(choices=[1, 2, 3, 4, 5], label=q) #, value=5
|
21 |
+
return q
|
22 |
+
|
23 |
+
def calculate_personality_score(questions, list_questions):
|
24 |
+
personality = {
|
25 |
+
'Extraversion': 0,
|
26 |
+
'Agreeableness': 0,
|
27 |
+
'Conscientiousness': 0,
|
28 |
+
'Neuroticism': 0,
|
29 |
+
'Openness': 0
|
30 |
+
}
|
31 |
+
for question in list_questions:
|
32 |
+
big_5_indicator = questions[question[0]]
|
33 |
+
score = correct_score(question[1], big_5_indicator=big_5_indicator)
|
34 |
+
personality[score[0]] += score[1]
|
35 |
+
return personality
|
36 |
+
|
37 |
+
import gradio as gr
|
38 |
+
import pandas as pd
|
39 |
+
import numpy as np
|
40 |
+
import os
|
41 |
+
|
42 |
+
#
|
43 |
+
df_big5_test = pd.read_csv('Big5.csv', sep=';', header=None)
|
44 |
+
df_big5_test = df_big5_test[[0, 6]]
|
45 |
+
df_big5_test.columns = ['question', 'score']
|
46 |
+
df_big5_test['score'] = df_big5_test['score'].apply(lambda x : x.replace('(', '').replace(')', '')[::-1])
|
47 |
+
# df.index = df.pop('question')
|
48 |
+
questions = dict()
|
49 |
+
for el in df_big5_test.values.tolist():
|
50 |
+
questions[el[0]] = el[1]
|
51 |
+
questions
|
52 |
+
|
53 |
+
#the first module becomes text1, the second module file1
|
54 |
+
def greet(*args):
|
55 |
+
args_list = [item for item in args]
|
56 |
+
|
57 |
+
#extract big5
|
58 |
+
q_list = list(questions)
|
59 |
+
a_list = args_list[6:]
|
60 |
+
list_total = [[q_list[x], a_list[x]] for x in range(len(a_list))]
|
61 |
+
personality = calculate_personality_score(questions, list_total)
|
62 |
+
personality = { x : dict1[x]/50 for x in dict1}
|
63 |
+
# personality = [personality['Openness'], personality['Conscientiousness'], personality['Extraversion'], personality['Agreeableness'], personality['Neuroticism']]
|
64 |
+
# personality = [x/50 for x in personality]
|
65 |
+
|
66 |
+
#to return a file:
|
67 |
+
#return 'new.xlsx'
|
68 |
+
return personality
|
69 |
+
|
70 |
+
iface = gr.Interface(
|
71 |
+
fn=greet,
|
72 |
+
inputs=[make_question(q) for q in list(questions)],
|
73 |
+
outputs=["text"]
|
74 |
+
)
|
75 |
+
iface.launch()
|
big5_gradio.ipynb
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"metadata": {},
|
6 |
+
"source": [
|
7 |
+
"https://ipip.ori.org/New_IPIP-50-item-scale.htm"
|
8 |
+
]
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"cell_type": "markdown",
|
12 |
+
"metadata": {},
|
13 |
+
"source": [
|
14 |
+
"# gradio"
|
15 |
+
]
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"execution_count": 14,
|
20 |
+
"metadata": {},
|
21 |
+
"outputs": [],
|
22 |
+
"source": [
|
23 |
+
"#os.system('pip install openpyxl') #works for huggingface-spaces\n",
|
24 |
+
"#score of each latent variable ranges in [10, 50]\n",
|
25 |
+
"def correct_score(score, big_5_indicator):\n",
|
26 |
+
" big_5_sign = big_5_indicator[0]\n",
|
27 |
+
" big_5_num = int(big_5_indicator[1])\n",
|
28 |
+
" dict1 = {\n",
|
29 |
+
" 1 : 'Extraversion',\n",
|
30 |
+
" 2 : 'Agreeableness',\n",
|
31 |
+
" 3 : 'Conscientiousness',\n",
|
32 |
+
" 4 : 'Neuroticism',\n",
|
33 |
+
" 5 : 'Openness'\n",
|
34 |
+
" }\n",
|
35 |
+
" if big_5_sign=='+':\n",
|
36 |
+
" return [dict1[big_5_num], score]\n",
|
37 |
+
" elif big_5_sign =='-':\n",
|
38 |
+
" return [dict1[big_5_num], 6-score]\n",
|
39 |
+
"# correct_score(3, big_5_indicator='-2')\n",
|
40 |
+
"\n",
|
41 |
+
"def make_question(q):\n",
|
42 |
+
" q = gr.Radio(choices=[1, 2, 3, 4, 5], label=q) #, value=5\n",
|
43 |
+
" return q\n",
|
44 |
+
"\n",
|
45 |
+
"def calculate_personality_score(questions, list_questions):\n",
|
46 |
+
" personality = {\n",
|
47 |
+
" 'Extraversion': 0,\n",
|
48 |
+
" 'Agreeableness': 0,\n",
|
49 |
+
" 'Conscientiousness': 0,\n",
|
50 |
+
" 'Neuroticism': 0,\n",
|
51 |
+
" 'Openness': 0\n",
|
52 |
+
" }\n",
|
53 |
+
" for question in list_questions:\n",
|
54 |
+
" big_5_indicator = questions[question[0]]\n",
|
55 |
+
" score = correct_score(question[1], big_5_indicator=big_5_indicator)\n",
|
56 |
+
" personality[score[0]] += score[1]\n",
|
57 |
+
" return personality"
|
58 |
+
]
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"cell_type": "code",
|
62 |
+
"execution_count": 24,
|
63 |
+
"metadata": {},
|
64 |
+
"outputs": [
|
65 |
+
{
|
66 |
+
"name": "stdout",
|
67 |
+
"output_type": "stream",
|
68 |
+
"text": [
|
69 |
+
"Running on local URL: http://127.0.0.1:7868\n",
|
70 |
+
"\n",
|
71 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
72 |
+
]
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"data": {
|
76 |
+
"text/html": [
|
77 |
+
"<div><iframe src=\"http://127.0.0.1:7868/\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
78 |
+
],
|
79 |
+
"text/plain": [
|
80 |
+
"<IPython.core.display.HTML object>"
|
81 |
+
]
|
82 |
+
},
|
83 |
+
"metadata": {},
|
84 |
+
"output_type": "display_data"
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"data": {
|
88 |
+
"text/plain": [
|
89 |
+
"(<gradio.routes.App at 0x15ecde2ab80>, 'http://127.0.0.1:7868/', None)"
|
90 |
+
]
|
91 |
+
},
|
92 |
+
"execution_count": 24,
|
93 |
+
"metadata": {},
|
94 |
+
"output_type": "execute_result"
|
95 |
+
}
|
96 |
+
],
|
97 |
+
"source": [
|
98 |
+
"import gradio as gr\n",
|
99 |
+
"import pandas as pd\n",
|
100 |
+
"import numpy as np\n",
|
101 |
+
"import os\n",
|
102 |
+
"\n",
|
103 |
+
"#\n",
|
104 |
+
"df_big5_test = pd.read_csv('Big5.csv', sep=';', header=None)\n",
|
105 |
+
"df_big5_test = df_big5_test[[0, 6]]\n",
|
106 |
+
"df_big5_test.columns = ['question', 'score']\n",
|
107 |
+
"df_big5_test['score'] = df_big5_test['score'].apply(lambda x : x.replace('(', '').replace(')', '')[::-1])\n",
|
108 |
+
"# df.index = df.pop('question')\n",
|
109 |
+
"questions = dict()\n",
|
110 |
+
"for el in df_big5_test.values.tolist():\n",
|
111 |
+
" questions[el[0]] = el[1]\n",
|
112 |
+
"questions\n",
|
113 |
+
"\n",
|
114 |
+
"#the first module becomes text1, the second module file1\n",
|
115 |
+
"def greet(*args): \n",
|
116 |
+
" args_list = [item for item in args]\n",
|
117 |
+
"\n",
|
118 |
+
" #extract big5\n",
|
119 |
+
" q_list = list(questions)\n",
|
120 |
+
" a_list = args_list[6:]\n",
|
121 |
+
" list_total = [[q_list[x], a_list[x]] for x in range(len(a_list))]\n",
|
122 |
+
" personality = calculate_personality_score(questions, list_total)\n",
|
123 |
+
" personality = { x : dict1[x]/50 for x in dict1}\n",
|
124 |
+
" # personality = [personality['Openness'], personality['Conscientiousness'], personality['Extraversion'], personality['Agreeableness'], personality['Neuroticism']]\n",
|
125 |
+
" # personality = [x/50 for x in personality]\n",
|
126 |
+
"\n",
|
127 |
+
" #to return a file:\n",
|
128 |
+
" #return 'new.xlsx'\n",
|
129 |
+
" return personality\n",
|
130 |
+
"\n",
|
131 |
+
"iface = gr.Interface(\n",
|
132 |
+
" fn=greet, \n",
|
133 |
+
" inputs=[make_question(q) for q in list(questions)], \n",
|
134 |
+
" outputs=[\"text\"]\n",
|
135 |
+
" )\n",
|
136 |
+
"iface.launch(share=False)"
|
137 |
+
]
|
138 |
+
}
|
139 |
+
],
|
140 |
+
"metadata": {
|
141 |
+
"kernelspec": {
|
142 |
+
"display_name": "Python 3.9.0 64-bit",
|
143 |
+
"language": "python",
|
144 |
+
"name": "python3"
|
145 |
+
},
|
146 |
+
"language_info": {
|
147 |
+
"codemirror_mode": {
|
148 |
+
"name": "ipython",
|
149 |
+
"version": 3
|
150 |
+
},
|
151 |
+
"file_extension": ".py",
|
152 |
+
"mimetype": "text/x-python",
|
153 |
+
"name": "python",
|
154 |
+
"nbconvert_exporter": "python",
|
155 |
+
"pygments_lexer": "ipython3",
|
156 |
+
"version": "3.9.0"
|
157 |
+
},
|
158 |
+
"orig_nbformat": 4,
|
159 |
+
"vscode": {
|
160 |
+
"interpreter": {
|
161 |
+
"hash": "fdf377d643bc1cb065454f0ad2ceac75d834452ecf289e7ba92c6b3f59a7cee1"
|
162 |
+
}
|
163 |
+
}
|
164 |
+
},
|
165 |
+
"nbformat": 4,
|
166 |
+
"nbformat_minor": 2
|
167 |
+
}
|