Mantis-to-human / app.py
Enoder's picture
Update app.py
30222ce verified
Raw
History Blame Contribute Delete
3.99 kB
import gradio as gr
# === Conversion pour Acontista mexicana ===
def age_humain_acontista(mois: float) -> float:
"""Conversion Acontista mexicana."""
if mois <= 1:
return 3 * mois
elif mois <= 2:
return 3 + (mois - 1) * 7
elif mois <= 3.5:
return 10 + (mois - 2) * 6.67
elif mois <= 4:
return 20 + (mois - 3.5) * 14
elif mois <= 6:
return 27 + (mois - 4) * 16.5
elif mois <= 10:
return 60 + (mois - 6) * 10
else:
return 100
# === Conversion pour Hierodula spp. ===
def age_humain_hierodula(stade: str = None, mois: float = None, sexe: str = "Femelle") -> float:
"""Conversion Hierodula spp. selon les données de Ruben."""
stades_mois = {
"L1": 0,
"L2": 0.5,
"L3": 1.25,
"L4": 2.125,
"L5": 3.125,
"L6": 4.625,
"L7": 6.825,
"L8": 9.325,
}
# Si on a donné un stade
if stade:
mois = stades_mois.get(stade, 0)
# Durée adulte selon le sexe
if sexe == "Mâle":
max_vie = 17 # ~L8 + 7.5 mois
elif sexe == "Femelle":
max_vie = 19.5 # ~L8 + 10 mois
else:
max_vie = 18.5
# Conversion en âge humain
if mois <= 9.325:
age_humain = (mois / 9.325) * 27
else:
age_humain = 27 + ((mois - 9.325) / (max_vie - 9.325)) * (100 - 27)
return min(age_humain, 100)
# === Gestion générale ===
def convertir_age(age_input, unite, espece, sexe):
espece = espece.lower()
if espece.startswith("acontista"):
if unite == "Stade":
return "Pour Acontista, indique l'âge en mois."
try:
mois = float(age_input)
except:
return "Entrée invalide pour l'âge."
age_humain = age_humain_acontista(mois)
return f"Âge humain approximatif : {age_humain:.1f} ans"
elif espece.startswith("hierodula"):
if unite == "Stade":
age_humain = age_humain_hierodula(stade=age_input, sexe=sexe)
else:
try:
mois = float(age_input)
except:
return "Entrée invalide pour l'âge."
age_humain = age_humain_hierodula(mois=mois, sexe=sexe)
return f"Âge humain approximatif : {age_humain:.1f} ans"
else:
return "Espèce non reconnue."
# === Interface Gradio ===
def main():
with gr.Blocks() as demo:
gr.Markdown("# 🦗 Convertisseur d’âge de mante religieuse en âge humain")
gr.Markdown("## Projet de Ruben — modèle expérimental basé sur *Acontista mexicana* et *Hierodula spp.*")
espece = gr.Radio(["Acontista mexicana", "Hierodula spp."], label="Espèce", value="Acontista mexicana")
unite = gr.Radio(["Mois", "Stade"], label="Type d’entrée", value="Mois")
age_input = gr.Dropdown(
["L1", "L2", "L3", "L4", "L5", "L6", "L7", "L8"],
label="Stade (si applicable)",
value="L1"
)
mois_input = gr.Number(label="Âge en mois (si applicable)", value=1.0)
sexe = gr.Radio(["Femelle", "Mâle", "Indéterminé"], label="Sexe", value="Femelle")
bouton = gr.Button("Convertir")
resultat = gr.Textbox(label="Résultat")
# Fonction liée au bouton
def process(espece, unite, stade, mois, sexe):
if unite == "Mois":
return convertir_age(mois, unite, espece, sexe)
else:
return convertir_age(stade, unite, espece, sexe)
bouton.click(process, [espece, unite, age_input, mois_input, sexe], resultat)
gr.Markdown(
"### ℹ️ Notes :\n"
"- Les équivalences sont basées sur des observations empiriques.\n"
"- Les *Acontista mexicana* se développent plus rapidement.\n"
"- Les *Hierodula spp.* ont un cycle de vie plus long et progressif.\n"
)
demo.launch()
if __name__ == "__main__":
main()