Enoder commited on
Commit
38b60e5
·
verified ·
1 Parent(s): c57adbe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()