Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,86 +1,126 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
1:
|
| 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 |
if unite == "Stade":
|
| 47 |
-
|
| 48 |
-
|
| 49 |
mois = float(age_input)
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
| 78 |
else:
|
| 79 |
-
return
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|