Update app.py
Browse files
app.py
CHANGED
@@ -93,34 +93,45 @@ def get_primary_input_name(model):
|
|
93 |
import time
|
94 |
import numpy as np
|
95 |
|
96 |
-
|
|
|
|
|
|
|
97 |
"""
|
98 |
-
Met à jour la barre
|
99 |
-
|
100 |
-
-
|
|
|
|
|
|
|
|
|
101 |
"""
|
102 |
if progress is None:
|
103 |
return
|
104 |
|
105 |
# normalisation
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
109 |
|
110 |
-
# récupérer
|
111 |
-
|
112 |
|
113 |
try:
|
114 |
-
if animate and val >
|
115 |
-
# interpolation
|
116 |
steps = 8
|
117 |
-
for step in np.linspace(
|
118 |
if desc:
|
119 |
progress(float(step), desc=desc)
|
120 |
else:
|
121 |
progress(float(step))
|
122 |
time.sleep(0.02) # vitesse de lissage
|
123 |
else:
|
|
|
124 |
if desc:
|
125 |
progress(val, desc=desc)
|
126 |
else:
|
@@ -128,8 +139,13 @@ def _update_progress(progress, value, desc=None, animate=True):
|
|
128 |
except Exception:
|
129 |
pass
|
130 |
|
|
|
131 |
progress._last_val = val
|
132 |
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# ---- PREDICT SINGLE ----
|
135 |
def predict_single(img_input, weights=(0.45, 0.25, 0.30), normalize=True):
|
|
|
93 |
import time
|
94 |
import numpy as np
|
95 |
|
96 |
+
import time
|
97 |
+
import numpy as np
|
98 |
+
|
99 |
+
def _update_progress(progress, 100, desc="Génération de la Carte Chaleur...", animate=False, sleep=0.05):
|
100 |
"""
|
101 |
+
Met à jour la barre de progression Gradio.
|
102 |
+
|
103 |
+
- progress : objet gr.Progress
|
104 |
+
- value : valeur cible (0–100 ou 0–1)
|
105 |
+
- desc : texte affiché
|
106 |
+
- animate : si True, interpolation fluide entre l'ancienne valeur et la nouvelle
|
107 |
+
- sleep : temps d'attente (secondes) après update, pour forcer l'UI à se rafraîchir
|
108 |
"""
|
109 |
if progress is None:
|
110 |
return
|
111 |
|
112 |
# normalisation
|
113 |
+
try:
|
114 |
+
val = float(value)
|
115 |
+
if val > 1.0:
|
116 |
+
val = val / 100.0
|
117 |
+
except Exception:
|
118 |
+
val = 0.0
|
119 |
|
120 |
+
# récupérer la dernière valeur connue
|
121 |
+
last_val = getattr(progress, "_last_val", 0.0)
|
122 |
|
123 |
try:
|
124 |
+
if animate and val > last_val:
|
125 |
+
# interpolation fluide
|
126 |
steps = 8
|
127 |
+
for step in np.linspace(last_val, val, steps):
|
128 |
if desc:
|
129 |
progress(float(step), desc=desc)
|
130 |
else:
|
131 |
progress(float(step))
|
132 |
time.sleep(0.02) # vitesse de lissage
|
133 |
else:
|
134 |
+
# mise à jour directe
|
135 |
if desc:
|
136 |
progress(val, desc=desc)
|
137 |
else:
|
|
|
139 |
except Exception:
|
140 |
pass
|
141 |
|
142 |
+
# sauvegarder la valeur pour la prochaine fois
|
143 |
progress._last_val = val
|
144 |
|
145 |
+
# petit délai optionnel pour forcer le rafraîchissement
|
146 |
+
if sleep > 0:
|
147 |
+
time.sleep(sleep)
|
148 |
+
|
149 |
|
150 |
# ---- PREDICT SINGLE ----
|
151 |
def predict_single(img_input, weights=(0.45, 0.25, 0.30), normalize=True):
|