clementBE commited on
Commit
686b41c
·
verified ·
1 Parent(s): 373fa5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -9
app.py CHANGED
@@ -9,9 +9,9 @@ from datetime import datetime
9
  # CONFIGURATION AND LANGUAGE DEFINITIONS
10
  # =================================================================
11
 
12
- # Setting EXPECTED_DATA_COUNT based on the final verified structure: 90
13
- EXPECTED_DATA_COUNT = 90
14
- EXPECTED_COUNT = 90
15
 
16
  # --- Shared Choices (French Only) ---
17
  FREQ_FR = ["Jamais", "Rarement", "Parfois", "Souvent"]
@@ -31,6 +31,16 @@ DOMAIN_CHOICES_FR = [
31
  "Ancrage local (bar associatif, aides aux personnes agées, bibliothèque associative…)",
32
  "autre - préciser"
33
  ]
 
 
 
 
 
 
 
 
 
 
34
  SOCIAL_MEDIA_CHOICES = [
35
  "Instagram", "YouTube", "TikTok", "Facebook", "WhatsApp", "BlueSky", "Signal",
36
  "Telegram", "Mastodon", "Discord", "Twitter", "Reddit", "messagerie de jeu en ligne",
@@ -109,7 +119,8 @@ LANG_FR = {
109
  "ENGAGE1_LABEL": "ENGAGE1 - Toi-même, participes-tu à des pratiques d’engagement citoyen ?",
110
  "ENGAGEMENT_ORGANISATION_LABEL": "ENGAGE2 - Dans quelle(s) organisation(s) es-tu engagé·e ?",
111
  "ENGAGE2_AUTRE_DETAIL_LABEL": "ENGAGE2 - Précisez 'autre'",
112
- "ENGAGEMENT_DOMAINE_LABEL": "ENGAGE3 - Dans quel domaine ? (Si engagé·e)",
 
113
  "INFO_ACTIVITES_LABEL": "ENGAGE4 - Participes-tu ou as-tu participé à une ou plusieurs des activités suivantes ?",
114
  "INFO_RESEAUX_SOCIAUX_LABEL": "ENGAGE5 - Utilises-tu les réseaux sociaux pour t’engager dans des causes ?",
115
  "INFO_FREQUENCE_ACTU_LABEL": "INFO1 - À quelle fréquence te tiens-tu informé·e de l’actualité ?",
@@ -186,7 +197,6 @@ space7_2 = gr.Textbox(label="Pratique 2", placeholder="Décrivez la pratique d'e
186
  space7_3 = gr.Textbox(label="Pratique 3", placeholder="Décrivez la pratique d'engagement 3", visible=False)
187
 
188
  # Domaine components (CheckboxGroup)
189
- # FIX: Changement de gr.Radio à gr.CheckboxGroup
190
  space_domain_1 = gr.CheckboxGroup(label=f"Domaines pour Pratique 1", choices=DOMAIN_CHOICES_FR, visible=False)
191
  space_domain_2 = gr.CheckboxGroup(label=f"Domaines pour Pratique 2", choices=DOMAIN_CHOICES_FR, visible=False)
192
  space_domain_3 = gr.CheckboxGroup(label=f"Domaines pour Pratique 3", choices=DOMAIN_CHOICES_FR, visible=False)
@@ -197,7 +207,11 @@ space11 = gr.CheckboxGroup(label=LANG["SPACE11_LABEL"], choices=SOCIAL_MEDIA_CHO
197
  engage1_role = gr.CheckboxGroup(label=LANG["ENGAGE1_LABEL"], choices=ENGAGE1_CHOICES)
198
  engage2_type = gr.CheckboxGroup(label=LANG["ENGAGEMENT_ORGANISATION_LABEL"], choices=ENGAGE2_CHOICES)
199
  engage2_autre_detail = gr.Textbox(label=LANG["ENGAGE2_AUTRE_DETAIL_LABEL"], visible=False)
200
- engagement_domaine = gr.Textbox(label=LANG["ENGAGEMENT_DOMAINE_LABEL"], placeholder="Domaine de l'engagement...")
 
 
 
 
201
  info_activites = gr.CheckboxGroup(label=LANG["INFO_ACTIVITES_LABEL"], choices=["Participer à une manifestation/grève", "Contacter un élu", "Signer une pétition en ligne", "Boycotter un produit/marque", "Faire un don à une association", "Autre"], interactive=True)
202
  info_reseaux_sociaux = gr.Radio(label=LANG["INFO_RESEAUX_SOCIAUX_LABEL"], choices=["Oui", "Non", "Parfois"])
203
 
@@ -295,7 +309,10 @@ def get_column_names(data_components: list) -> list:
295
  clean_name = "SPACE4_QUAL_3"
296
  elif clean_name == "ENGAGE2_Précisez_'autre'":
297
  clean_name = "ENGAGE2_Autre_Precision"
298
-
 
 
 
299
  names.append(clean_name)
300
  else:
301
  names.append(f"Component_{i+1}")
@@ -367,6 +384,10 @@ def update_domain_visibility(practice_text):
367
  def update_visibility_engage2_autre(engage2_choices: List[str]):
368
  return gr.update(visible="autre (préciser)" in engage2_choices)
369
 
 
 
 
 
370
  def process_survey(*data_values: Any) -> Tuple[str, gr.File]:
371
  """
372
  Processes survey data, creates a temporary CSV file, and returns the path
@@ -427,8 +448,10 @@ DATA_INPUT_COMPONENTS = [
427
  space7_2, space_domain_2,
428
  space7_3, space_domain_3,
429
  space11,
430
- # TAB 2 - Engagement (6)
431
- engage1_role, engage2_type, engage2_autre_detail, engagement_domaine, info_activites, info_reseaux_sociaux,
 
 
432
  # TAB 3 - Actualité (16)
433
  info_frequence_actu, info2, info3, info_opposite_feeling, info_contradict_opinion,
434
  info4, info5,
@@ -560,7 +583,11 @@ with gr.Blocks(title=LANG["TITLE"], css=".gradio-container { max-width: 1200px;
560
  engage1_role.render()
561
  engage2_type.render()
562
  engage2_autre_detail.render()
 
 
563
  engagement_domaine.render()
 
 
564
  info_activites.render()
565
  info_reseaux_sociaux.render()
566
 
@@ -569,6 +596,13 @@ with gr.Blocks(title=LANG["TITLE"], css=".gradio-container { max-width: 1200px;
569
  inputs=[engage2_type],
570
  outputs=[engage2_autre_detail]
571
  )
 
 
 
 
 
 
 
572
 
573
 
574
  # =================================================================
 
9
  # CONFIGURATION AND LANGUAGE DEFINITIONS
10
  # =================================================================
11
 
12
+ # Setting EXPECTED_DATA_COUNT based on the final verified structure: 91
13
+ EXPECTED_DATA_COUNT = 91
14
+ EXPECTED_COUNT = 91
15
 
16
  # --- Shared Choices (French Only) ---
17
  FREQ_FR = ["Jamais", "Rarement", "Parfois", "Souvent"]
 
31
  "Ancrage local (bar associatif, aides aux personnes agées, bibliothèque associative…)",
32
  "autre - préciser"
33
  ]
34
+ # NOUVELLE LISTE POUR ENGAGE3
35
+ ENGAGE3_CHOICES_FR = [
36
+ "écologie",
37
+ "lutte contre la pauvreté",
38
+ "action contre les discriminations",
39
+ "vie politique locale ou nationale",
40
+ "action syndicale",
41
+ "causes internationales",
42
+ "autre / précisez"
43
+ ]
44
  SOCIAL_MEDIA_CHOICES = [
45
  "Instagram", "YouTube", "TikTok", "Facebook", "WhatsApp", "BlueSky", "Signal",
46
  "Telegram", "Mastodon", "Discord", "Twitter", "Reddit", "messagerie de jeu en ligne",
 
119
  "ENGAGE1_LABEL": "ENGAGE1 - Toi-même, participes-tu à des pratiques d’engagement citoyen ?",
120
  "ENGAGEMENT_ORGANISATION_LABEL": "ENGAGE2 - Dans quelle(s) organisation(s) es-tu engagé·e ?",
121
  "ENGAGE2_AUTRE_DETAIL_LABEL": "ENGAGE2 - Précisez 'autre'",
122
+ "ENGAGEMENT_DOMAINE_LABEL": "ENGAGE3 - Dans quel(s) domaine(s) es-tu engagé·e ?",
123
+ "ENGAGE3_AUTRE_DETAIL_LABEL": "ENGAGE3 - Précisez 'autre'", # NOUVELLE ÉTIQUETTE
124
  "INFO_ACTIVITES_LABEL": "ENGAGE4 - Participes-tu ou as-tu participé à une ou plusieurs des activités suivantes ?",
125
  "INFO_RESEAUX_SOCIAUX_LABEL": "ENGAGE5 - Utilises-tu les réseaux sociaux pour t’engager dans des causes ?",
126
  "INFO_FREQUENCE_ACTU_LABEL": "INFO1 - À quelle fréquence te tiens-tu informé·e de l’actualité ?",
 
197
  space7_3 = gr.Textbox(label="Pratique 3", placeholder="Décrivez la pratique d'engagement 3", visible=False)
198
 
199
  # Domaine components (CheckboxGroup)
 
200
  space_domain_1 = gr.CheckboxGroup(label=f"Domaines pour Pratique 1", choices=DOMAIN_CHOICES_FR, visible=False)
201
  space_domain_2 = gr.CheckboxGroup(label=f"Domaines pour Pratique 2", choices=DOMAIN_CHOICES_FR, visible=False)
202
  space_domain_3 = gr.CheckboxGroup(label=f"Domaines pour Pratique 3", choices=DOMAIN_CHOICES_FR, visible=False)
 
207
  engage1_role = gr.CheckboxGroup(label=LANG["ENGAGE1_LABEL"], choices=ENGAGE1_CHOICES)
208
  engage2_type = gr.CheckboxGroup(label=LANG["ENGAGEMENT_ORGANISATION_LABEL"], choices=ENGAGE2_CHOICES)
209
  engage2_autre_detail = gr.Textbox(label=LANG["ENGAGE2_AUTRE_DETAIL_LABEL"], visible=False)
210
+
211
+ # ENGAGE3 : Changement de Textbox à CheckboxGroup + Textbox pour 'autre'
212
+ engagement_domaine = gr.CheckboxGroup(label=LANG["ENGAGEMENT_DOMAINE_LABEL"], choices=ENGAGE3_CHOICES_FR)
213
+ engage3_autre_detail = gr.Textbox(label=LANG["ENGAGE3_AUTRE_DETAIL_LABEL"], visible=False)
214
+
215
  info_activites = gr.CheckboxGroup(label=LANG["INFO_ACTIVITES_LABEL"], choices=["Participer à une manifestation/grève", "Contacter un élu", "Signer une pétition en ligne", "Boycotter un produit/marque", "Faire un don à une association", "Autre"], interactive=True)
216
  info_reseaux_sociaux = gr.Radio(label=LANG["INFO_RESEAUX_SOCIAUX_LABEL"], choices=["Oui", "Non", "Parfois"])
217
 
 
309
  clean_name = "SPACE4_QUAL_3"
310
  elif clean_name == "ENGAGE2_Précisez_'autre'":
311
  clean_name = "ENGAGE2_Autre_Precision"
312
+ # NOUVEAU NOM DE COLONNE POUR ENGAGE3_AUTRE
313
+ elif clean_name == "ENGAGE3_Précisez_'autre'":
314
+ clean_name = "ENGAGE3_Autre_Precision"
315
+
316
  names.append(clean_name)
317
  else:
318
  names.append(f"Component_{i+1}")
 
384
  def update_visibility_engage2_autre(engage2_choices: List[str]):
385
  return gr.update(visible="autre (préciser)" in engage2_choices)
386
 
387
+ # NOUVELLE FONCTION de visibilité pour ENGAGE3
388
+ def update_visibility_engage3_autre(engage3_choices: List[str]):
389
+ return gr.update(visible="autre / précisez" in engage3_choices)
390
+
391
  def process_survey(*data_values: Any) -> Tuple[str, gr.File]:
392
  """
393
  Processes survey data, creates a temporary CSV file, and returns the path
 
448
  space7_2, space_domain_2,
449
  space7_3, space_domain_3,
450
  space11,
451
+ # TAB 2 - Engagement (7 composants au lieu de 6)
452
+ engage1_role, engage2_type, engage2_autre_detail,
453
+ engagement_domaine, engage3_autre_detail, # NOUVEAU: Textbox pour ENGAGE3 'autre'
454
+ info_activites, info_reseaux_sociaux,
455
  # TAB 3 - Actualité (16)
456
  info_frequence_actu, info2, info3, info_opposite_feeling, info_contradict_opinion,
457
  info4, info5,
 
583
  engage1_role.render()
584
  engage2_type.render()
585
  engage2_autre_detail.render()
586
+
587
+ # ENGAGE3 - Domaine de l'engagement (CheckboxGroup)
588
  engagement_domaine.render()
589
+ engage3_autre_detail.render() # Champ de précision pour 'autre'
590
+
591
  info_activites.render()
592
  info_reseaux_sociaux.render()
593
 
 
596
  inputs=[engage2_type],
597
  outputs=[engage2_autre_detail]
598
  )
599
+
600
+ # NOUVELLE LOGIQUE pour ENGAGE3 'autre'
601
+ engagement_domaine.change(
602
+ fn=update_visibility_engage3_autre,
603
+ inputs=[engagement_domaine],
604
+ outputs=[engage3_autre_detail]
605
+ )
606
 
607
 
608
  # =================================================================