Enoder commited on
Commit
30222ce
·
verified ·
1 Parent(s): 1c31cff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -62
app.py CHANGED
@@ -1,86 +1,126 @@
1
  import gradio as gr
2
- import numpy as np
3
-
4
- # Conversion pour Acontista mexicana (approximation par interpolation)
5
- acontista_data = {
6
- 1: 3,
7
- 2: 10,
8
- 3.5: 20,
9
- 4: 27,
10
- 6: 60,
11
- 10: 100
12
- }
13
-
14
- def interp_age_acontista(mois):
15
- mois_list = sorted(acontista_data.keys())
16
- ans_list = [acontista_data[m] for m in mois_list]
17
- return np.interp(mois, mois_list, ans_list)
18
-
19
- # Conversion pour Hierodula spp.
20
- hierodula_stades = {
21
- "L1": 0,
22
- "L2": 0.5,
23
- "L3": 1.25,
24
- "L4": 2.125,
25
- "L5": 3.125,
26
- "L6": 4.625,
27
- "L7": 6.825,
28
- "L8": 9.325, # Adulte
29
- }
30
-
31
- def hierodula_age_mois(stade, sexe):
32
- base = hierodula_stades.get(stade, 0)
33
- if stade == "L8": # adulte
34
- if sexe == "Mâle":
35
- return base + 4.5 # vie adulte plus courte
36
- else:
37
- return base + 7 # femelle plus longue
38
- return base
39
-
40
- def convert_age(age_input, unite, espece, sexe):
41
- # Conversion selon l'espèce
42
- if espece == "Acontista mexicana":
43
- mois = float(age_input)
44
- age_humain = interp_age_acontista(mois)
45
- elif espece == "Hierodula spp.":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  if unite == "Stade":
47
- mois = hierodula_age_mois(age_input, sexe)
48
- else:
49
  mois = float(age_input)
50
- # On fait correspondre 10 mois ≈ 100 ans (même base que Acontista)
51
- age_humain = (mois / 10) * 100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  else:
53
  return "Espèce non reconnue."
54
 
55
- return f"Âge humain approximatif : {age_humain:.1f} ans"
56
 
57
- # Interface Gradio
58
  def main():
59
  with gr.Blocks() as demo:
60
- gr.Markdown("# 🦗 Convertisseur d’âge de mante en âge humain")
 
 
 
 
61
 
62
- espece = gr.Radio(["Acontista mexicana", "Hierodula spp."], label="Espèce")
63
- unite = gr.Radio(["Stade", "Mois"], label="Type d'entrée")
64
  age_input = gr.Dropdown(
65
- ["L1","L2","L3","L4","L5","L6","L7","L8"],
66
- label="Stade (si sélectionné)",
67
  value="L1"
68
  )
69
  mois_input = gr.Number(label="Âge en mois (si applicable)", value=1.0)
70
  sexe = gr.Radio(["Femelle", "Mâle", "Indéterminé"], label="Sexe", value="Femelle")
71
 
72
- btn = gr.Button("Convertir")
73
- output = gr.Textbox(label="Résultat")
74
 
75
- def process(espece, unite, age, mois, sexe):
76
- if unite == "Stade":
77
- return convert_age(age, unite, espece, sexe)
 
78
  else:
79
- return convert_age(mois, unite, espece, sexe)
80
 
81
- btn.click(process, [espece, unite, age_input, mois_input, sexe], output)
 
 
 
 
 
 
 
82
 
83
  demo.launch()
84
 
 
85
  if __name__ == "__main__":
86
  main()
 
1
  import gradio as gr
2
+
3
+ # === Conversion pour Acontista mexicana ===
4
+ def age_humain_acontista(mois: float) -> float:
5
+ """Conversion Acontista mexicana."""
6
+ if mois <= 1:
7
+ return 3 * mois
8
+ elif mois <= 2:
9
+ return 3 + (mois - 1) * 7
10
+ elif mois <= 3.5:
11
+ return 10 + (mois - 2) * 6.67
12
+ elif mois <= 4:
13
+ return 20 + (mois - 3.5) * 14
14
+ elif mois <= 6:
15
+ return 27 + (mois - 4) * 16.5
16
+ elif mois <= 10:
17
+ return 60 + (mois - 6) * 10
18
+ else:
19
+ return 100
20
+
21
+
22
+ # === Conversion pour Hierodula spp. ===
23
+ def age_humain_hierodula(stade: str = None, mois: float = None, sexe: str = "Femelle") -> float:
24
+ """Conversion Hierodula spp. selon les données de Ruben."""
25
+ stades_mois = {
26
+ "L1": 0,
27
+ "L2": 0.5,
28
+ "L3": 1.25,
29
+ "L4": 2.125,
30
+ "L5": 3.125,
31
+ "L6": 4.625,
32
+ "L7": 6.825,
33
+ "L8": 9.325,
34
+ }
35
+
36
+ # Si on a donné un stade
37
+ if stade:
38
+ mois = stades_mois.get(stade, 0)
39
+
40
+ # Durée adulte selon le sexe
41
+ if sexe == "Mâle":
42
+ max_vie = 17 # ~L8 + 7.5 mois
43
+ elif sexe == "Femelle":
44
+ max_vie = 19.5 # ~L8 + 10 mois
45
+ else:
46
+ max_vie = 18.5
47
+
48
+ # Conversion en âge humain
49
+ if mois <= 9.325:
50
+ age_humain = (mois / 9.325) * 27
51
+ else:
52
+ age_humain = 27 + ((mois - 9.325) / (max_vie - 9.325)) * (100 - 27)
53
+
54
+ return min(age_humain, 100)
55
+
56
+
57
+ # === Gestion générale ===
58
+ def convertir_age(age_input, unite, espece, sexe):
59
+ espece = espece.lower()
60
+
61
+ if espece.startswith("acontista"):
62
  if unite == "Stade":
63
+ return "Pour Acontista, indique l'âge en mois."
64
+ try:
65
  mois = float(age_input)
66
+ except:
67
+ return "Entrée invalide pour l'âge."
68
+ age_humain = age_humain_acontista(mois)
69
+ return f"Âge humain approximatif : {age_humain:.1f} ans"
70
+
71
+ elif espece.startswith("hierodula"):
72
+ if unite == "Stade":
73
+ age_humain = age_humain_hierodula(stade=age_input, sexe=sexe)
74
+ else:
75
+ try:
76
+ mois = float(age_input)
77
+ except:
78
+ return "Entrée invalide pour l'âge."
79
+ age_humain = age_humain_hierodula(mois=mois, sexe=sexe)
80
+ return f"Âge humain approximatif : {age_humain:.1f} ans"
81
+
82
  else:
83
  return "Espèce non reconnue."
84
 
 
85
 
86
+ # === Interface Gradio ===
87
  def main():
88
  with gr.Blocks() as demo:
89
+ gr.Markdown("# 🦗 Convertisseur d’âge de mante religieuse en âge humain")
90
+ gr.Markdown("## Projet de Ruben — modèle expérimental basé sur *Acontista mexicana* et *Hierodula spp.*")
91
+
92
+ espece = gr.Radio(["Acontista mexicana", "Hierodula spp."], label="Espèce", value="Acontista mexicana")
93
+ unite = gr.Radio(["Mois", "Stade"], label="Type d’entrée", value="Mois")
94
 
 
 
95
  age_input = gr.Dropdown(
96
+ ["L1", "L2", "L3", "L4", "L5", "L6", "L7", "L8"],
97
+ label="Stade (si applicable)",
98
  value="L1"
99
  )
100
  mois_input = gr.Number(label="Âge en mois (si applicable)", value=1.0)
101
  sexe = gr.Radio(["Femelle", "Mâle", "Indéterminé"], label="Sexe", value="Femelle")
102
 
103
+ bouton = gr.Button("Convertir")
104
+ resultat = gr.Textbox(label="Résultat")
105
 
106
+ # Fonction liée au bouton
107
+ def process(espece, unite, stade, mois, sexe):
108
+ if unite == "Mois":
109
+ return convertir_age(mois, unite, espece, sexe)
110
  else:
111
+ return convertir_age(stade, unite, espece, sexe)
112
 
113
+ bouton.click(process, [espece, unite, age_input, mois_input, sexe], resultat)
114
+
115
+ gr.Markdown(
116
+ "### ℹ️ Notes :\n"
117
+ "- Les équivalences sont basées sur des observations empiriques.\n"
118
+ "- Les *Acontista mexicana* se développent plus rapidement.\n"
119
+ "- Les *Hierodula spp.* ont un cycle de vie plus long et progressif.\n"
120
+ )
121
 
122
  demo.launch()
123
 
124
+
125
  if __name__ == "__main__":
126
  main()