benjaminBeuster commited on
Commit
d86cab2
Β·
verified Β·
1 Parent(s): b74f9a2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +48 -29
app.py CHANGED
@@ -59,35 +59,38 @@ def classify_text(text):
59
  return output
60
 
61
  # Example questions - mix of actual ESS data and generated diverse questions
62
- examples = [
63
- # EDUCATION (most common - 146 samples)
 
 
 
64
  ["What is the highest level of education you have successfully completed?"],
65
  ["What is the highest level of education your mother successfully completed?"],
66
  ["How many years of full-time education have you completed?"],
67
 
68
- # POLITICS (100 samples)
69
  ["Which party did you vote for in the last national election?"],
70
  ["Trust in country's parliament"],
71
  ["How satisfied are you with the way democracy works in your country?"],
72
  ["How much do you trust the legal system?"],
73
 
74
- # HEALTH (90 samples)
75
  ["How satisfied are you with the healthcare system?"],
76
  ["Which health problems that you had in the last 12 months hampered you in your daily activities?"],
77
  ["How is your health in general - very good, good, fair, bad, or very bad?"],
78
 
79
- # LABOUR AND EMPLOYMENT (82 samples)
80
  ["What best describes what you have been doing for the last 7 days - in paid work?"],
81
  ["Which description best describes the sort of work your mother did when you were 14?"],
82
  ["How many hours do you normally work per week in your main job?"],
83
  ["Are you a member of a trade union or similar organization?"],
84
 
85
- # SOCIETY AND CULTURE (73 samples)
86
  ["How often do you pray apart from at religious services?"],
87
  ["How important is it to always behave properly and avoid doing anything people would say is wrong?"],
88
  ["Do you consider yourself as belonging to any particular religion or denomination?"],
89
 
90
- # DEMOGRAPHY
91
  ["What is your age?"],
92
  ["What is your gender?"],
93
  ["What is your current legal marital status?"],
@@ -122,19 +125,35 @@ examples = [
122
  ["Do you rent or own your accommodation?"],
123
  ["How many rooms do you have for your household's use only?"],
124
 
125
- # SOCIAL WELFARE
126
  ["Should the government reduce income differences?"],
127
  ["How satisfied are you with the state of social benefits in your country?"],
128
 
129
- # TRANSPORT
130
  ["How long does your daily commute to work take?"],
131
  ["What is your main mode of transportation?"],
132
 
133
  # SCIENCE AND TECHNOLOGY
134
  ["To what extent do you think scientific advances benefit society?"],
135
  ["How often do you use a smartphone or tablet?"],
 
 
 
 
 
 
 
 
 
 
 
 
136
  ]
137
 
 
 
 
 
138
  # Custom CSS for Sikt branding using design tokens
139
  custom_css = """
140
  :root {
@@ -271,26 +290,26 @@ demo = gr.Interface(
271
  categorizing them into subject areas. The model was trained on European Social Survey metadata
272
  and can classify questions into <strong>19 categories</strong>:
273
  </p>
274
- <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 0.5rem; margin-top: 1rem;">
275
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ“š Education</span>
276
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ›οΈ Politics</span>
277
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ₯ Health</span>
278
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ’Ό Labour & Employment</span>
279
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">🌍 Society & Culture</span>
280
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ’° Economics</span>
281
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">🧠 Psychology</span>
282
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ‘₯ Demography</span>
283
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">🏠 Housing & Land Use</span>
284
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">🌱 Natural Environment</span>
285
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">βš–οΈ Law, Crime & Legal Systems</span>
286
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ“Ί Media, Communication & Language</span>
287
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ‘” Social Stratification & Groupings</span>
288
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">🀝 Social Welfare Policy & Systems</span>
289
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸš— Transport & Travel</span>
290
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸͺ Trade, Industry & Markets</span>
291
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ”¬ Science & Technology</span>
292
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ“œ History</span>
293
- <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.85rem; border-left: 3px solid #7d5da6;">πŸ“‹ Other</span>
294
  </div>
295
  </div>
296
 
 
59
  return output
60
 
61
  # Example questions - mix of actual ESS data and generated diverse questions
62
+ # Using exact category names from pydantic_classes.py
63
+ import random
64
+
65
+ all_examples = [
66
+ # EDUCATION
67
  ["What is the highest level of education you have successfully completed?"],
68
  ["What is the highest level of education your mother successfully completed?"],
69
  ["How many years of full-time education have you completed?"],
70
 
71
+ # POLITICS
72
  ["Which party did you vote for in the last national election?"],
73
  ["Trust in country's parliament"],
74
  ["How satisfied are you with the way democracy works in your country?"],
75
  ["How much do you trust the legal system?"],
76
 
77
+ # HEALTH
78
  ["How satisfied are you with the healthcare system?"],
79
  ["Which health problems that you had in the last 12 months hampered you in your daily activities?"],
80
  ["How is your health in general - very good, good, fair, bad, or very bad?"],
81
 
82
+ # LABOUR AND EMPLOYMENT
83
  ["What best describes what you have been doing for the last 7 days - in paid work?"],
84
  ["Which description best describes the sort of work your mother did when you were 14?"],
85
  ["How many hours do you normally work per week in your main job?"],
86
  ["Are you a member of a trade union or similar organization?"],
87
 
88
+ # SOCIETY AND CULTURE
89
  ["How often do you pray apart from at religious services?"],
90
  ["How important is it to always behave properly and avoid doing anything people would say is wrong?"],
91
  ["Do you consider yourself as belonging to any particular religion or denomination?"],
92
 
93
+ # DEMOGRAPHY (POPULATION, VITAL STATISTICS, AND CENSUSES)
94
  ["What is your age?"],
95
  ["What is your gender?"],
96
  ["What is your current legal marital status?"],
 
125
  ["Do you rent or own your accommodation?"],
126
  ["How many rooms do you have for your household's use only?"],
127
 
128
+ # SOCIAL WELFARE POLICY AND SYSTEMS
129
  ["Should the government reduce income differences?"],
130
  ["How satisfied are you with the state of social benefits in your country?"],
131
 
132
+ # TRANSPORT AND TRAVEL
133
  ["How long does your daily commute to work take?"],
134
  ["What is your main mode of transportation?"],
135
 
136
  # SCIENCE AND TECHNOLOGY
137
  ["To what extent do you think scientific advances benefit society?"],
138
  ["How often do you use a smartphone or tablet?"],
139
+
140
+ # HISTORY
141
+ ["What do you think about your country's colonial past?"],
142
+ ["How important is it to preserve historical monuments?"],
143
+
144
+ # TRADE, INDUSTRY AND MARKETS
145
+ ["Do you work in the private or public sector?"],
146
+ ["How do you feel about free trade agreements?"],
147
+
148
+ # OTHER
149
+ ["What are your thoughts on the future?"],
150
+ ["How do you define quality of life?"],
151
  ]
152
 
153
+ # Shuffle and select 30 examples
154
+ random.seed(42) # For reproducibility
155
+ examples = random.sample(all_examples, min(30, len(all_examples)))
156
+
157
  # Custom CSS for Sikt branding using design tokens
158
  custom_css = """
159
  :root {
 
290
  categorizing them into subject areas. The model was trained on European Social Survey metadata
291
  and can classify questions into <strong>19 categories</strong>:
292
  </p>
293
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0.5rem; margin-top: 1rem;">
294
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ“š EDUCATION</span>
295
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ›οΈ POLITICS</span>
296
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ₯ HEALTH</span>
297
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ’Ό LABOUR AND EMPLOYMENT</span>
298
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">🌍 SOCIETY AND CULTURE</span>
299
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ’° ECONOMICS</span>
300
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">🧠 PSYCHOLOGY</span>
301
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ‘₯ DEMOGRAPHY (POPULATION, VITAL STATISTICS, AND CENSUSES)</span>
302
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">🏠 HOUSING AND LAND USE</span>
303
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">🌱 NATURAL ENVIRONMENT</span>
304
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">βš–οΈ LAW, CRIME AND LEGAL SYSTEMS</span>
305
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ“Ί MEDIA, COMMUNICATION AND LANGUAGE</span>
306
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ‘” SOCIAL STRATIFICATION AND GROUPINGS</span>
307
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">🀝 SOCIAL WELFARE POLICY AND SYSTEMS</span>
308
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸš— TRANSPORT AND TRAVEL</span>
309
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸͺ TRADE, INDUSTRY AND MARKETS</span>
310
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ”¬ SCIENCE AND TECHNOLOGY</span>
311
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ“œ HISTORY</span>
312
+ <span style="padding: 0.5rem; background: white; border-radius: 4px; font-size: 0.8rem; border-left: 3px solid #7d5da6;">πŸ“‹ OTHER</span>
313
  </div>
314
  </div>
315