tiffank1802 commited on
Commit ·
e6392fe
1
Parent(s): 1388821
Ajout des fichiers supplémentaires et cache Python
Browse files- Ajout des versions de backup de l'application
- Inclusion du cache Python pour compatibilité
- Nettoyage complet du dépôt pour Hugging Face
- __pycache__/app.cpython-312.pyc +0 -0
- __pycache__/app_fixed.cpython-312.pyc +0 -0
- __pycache__/app_gradio.cpython-312.pyc +0 -0
- __pycache__/app_minimal.cpython-312.pyc +0 -0
- __pycache__/app_simple.cpython-312.pyc +0 -0
- __pycache__/app_ultra_simple.cpython-312.pyc +0 -0
- __pycache__/deviatoire.cpython-312.pyc +0 -0
- __pycache__/versDV.cpython-312.pyc +0 -0
- app_backup.py +355 -0
- app_simple.py +153 -0
__pycache__/app.cpython-312.pyc
ADDED
|
Binary file (10.6 kB). View file
|
|
|
__pycache__/app_fixed.cpython-312.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
__pycache__/app_gradio.cpython-312.pyc
ADDED
|
Binary file (13.8 kB). View file
|
|
|
__pycache__/app_minimal.cpython-312.pyc
ADDED
|
Binary file (4.26 kB). View file
|
|
|
__pycache__/app_simple.cpython-312.pyc
ADDED
|
Binary file (8.46 kB). View file
|
|
|
__pycache__/app_ultra_simple.cpython-312.pyc
ADDED
|
Binary file (5.91 kB). View file
|
|
|
__pycache__/deviatoire.cpython-312.pyc
ADDED
|
Binary file (3.03 kB). View file
|
|
|
__pycache__/versDV.cpython-312.pyc
ADDED
|
Binary file (13.2 kB). View file
|
|
|
app_backup.py
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 9 |
+
import base64
|
| 10 |
+
|
| 11 |
+
# CSS personnalisé avec les couleurs de l'école
|
| 12 |
+
css = """
|
| 13 |
+
/* Palette de couleurs Centrale Lyon (version rouge) */
|
| 14 |
+
:root {
|
| 15 |
+
--primary-red: #D52B1E;
|
| 16 |
+
--secondary-red: #B22222;
|
| 17 |
+
--accent-red: #8B0000;
|
| 18 |
+
--light-gray: #F5F5F5;
|
| 19 |
+
--dark-gray: #333333;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.gradio-container {
|
| 23 |
+
font-family: 'Arial', sans-serif;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
.main-header {
|
| 27 |
+
background: linear-gradient(90deg, var(--primary-red) 0%, var(--secondary-red) 100%);
|
| 28 |
+
padding: 1.5rem;
|
| 29 |
+
border-radius: 0 0 10px 10px;
|
| 30 |
+
color: white;
|
| 31 |
+
text-align: center;
|
| 32 |
+
margin-bottom: 2rem;
|
| 33 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.centrale-title {
|
| 37 |
+
font-family: 'Georgia', serif;
|
| 38 |
+
font-weight: 700;
|
| 39 |
+
margin-bottom: 0.5rem;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.centrale-subtitle {
|
| 43 |
+
font-family: 'Arial', sans-serif;
|
| 44 |
+
font-size: 1.2rem;
|
| 45 |
+
opacity: 0.9;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.centrale-card {
|
| 49 |
+
border-left: 4px solid var(--accent-red);
|
| 50 |
+
padding: 1rem;
|
| 51 |
+
background-color: var(--light-gray);
|
| 52 |
+
border-radius: 0 8px 8px 0;
|
| 53 |
+
margin: 1rem 0;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.footer {
|
| 57 |
+
background-color: var(--dark-gray);
|
| 58 |
+
color: white;
|
| 59 |
+
padding: 1rem;
|
| 60 |
+
text-align: center;
|
| 61 |
+
margin-top: 2rem;
|
| 62 |
+
border-radius: 8px 8px 0 0;
|
| 63 |
+
font-size: 0.9rem;
|
| 64 |
+
}
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
def create_header():
|
| 68 |
+
"""Crée le header HTML avec le style Centrale Lyon"""
|
| 69 |
+
return f"""
|
| 70 |
+
<div class="main-header">
|
| 71 |
+
<h1 class="centrale-title">ÉCOLE CENTRALE LYON</h1>
|
| 72 |
+
<h2 class="centrale-subtitle">Analyse de Fatigue - Critère de Dang Van</h2>
|
| 73 |
+
</div>
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
def create_info_panel():
|
| 77 |
+
"""Crée le panneau d'informations"""
|
| 78 |
+
return """
|
| 79 |
+
<div class="centrale-card">
|
| 80 |
+
<h3>📝 À propos du critère de Dang Van</h3>
|
| 81 |
+
<p>Le critère de Dang Van est un critère multiaxial de fatigue à haute durée de vie.
|
| 82 |
+
Il permet de prendre en compte l'effet de la pression hydrostatique sur l'endurance
|
| 83 |
+
en fatigue des matériaux métalliques. Cette application visualise le domaine de
|
| 84 |
+
sécurité défini par ce critère pour différents types de chargements.</p>
|
| 85 |
+
|
| 86 |
+
<h4>👥 Équipe</h4>
|
| 87 |
+
<p><strong>Étudiants :</strong> Kevin TONGUE, Paul LORTHIOIR</p>
|
| 88 |
+
<p><strong>Enseignants :</strong> Éric FEULVACH, Françoise FAUVIN</p>
|
| 89 |
+
<p><strong>UE :</strong> Projet de recherche et innovation</p>
|
| 90 |
+
<p><strong>Thème :</strong> Analyse en fatigue de structures industrielles soumises à des chargements complexes</p>
|
| 91 |
+
<p><strong>Date :</strong> 2026</p>
|
| 92 |
+
</div>
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
def calculate_dang_van(sigma1, omega, fin, pasTemps, point_size, show_grid, theme):
|
| 96 |
+
"""
|
| 97 |
+
Fonction principale de calcul pour le critère de Dang Van
|
| 98 |
+
"""
|
| 99 |
+
try:
|
| 100 |
+
# Configuration du style selon le thème choisi
|
| 101 |
+
if theme == "Moderne":
|
| 102 |
+
plt.style.use('seaborn-v0_8-darkgrid')
|
| 103 |
+
elif theme == "Scientifique":
|
| 104 |
+
plt.style.use('seaborn-v0_8-paper')
|
| 105 |
+
else:
|
| 106 |
+
plt.style.use('default')
|
| 107 |
+
|
| 108 |
+
# Calcul des points pour chargement uniaxial
|
| 109 |
+
points_uniaxial = dv.nuage(sigma1, omega, pasTemps, fin)
|
| 110 |
+
|
| 111 |
+
# Calcul des points pour torsion
|
| 112 |
+
points_torsion = dv.nuageOrt(sigma1, omega, pasTemps, fin)
|
| 113 |
+
|
| 114 |
+
# Préparation de la figure
|
| 115 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 116 |
+
|
| 117 |
+
# Tracé des points
|
| 118 |
+
scatter1 = ax.scatter(
|
| 119 |
+
points_uniaxial[:, 0],
|
| 120 |
+
points_uniaxial[:, 1],
|
| 121 |
+
s=point_size,
|
| 122 |
+
alpha=0.7,
|
| 123 |
+
label='Traction-Compression',
|
| 124 |
+
edgecolors='white',
|
| 125 |
+
linewidth=1
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
scatter2 = ax.scatter(
|
| 129 |
+
points_torsion[:, 0],
|
| 130 |
+
points_torsion[:, 1],
|
| 131 |
+
s=point_size,
|
| 132 |
+
alpha=0.7,
|
| 133 |
+
label='Torsion',
|
| 134 |
+
edgecolors='white',
|
| 135 |
+
linewidth=1
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
# Configuration des axes et titres
|
| 139 |
+
ax.set_xlabel("Pression hydrostatique (MPa)", fontsize=12, fontweight='bold')
|
| 140 |
+
ax.set_ylabel("Amplitude de cisaillement max (MPa)", fontsize=12, fontweight='bold')
|
| 141 |
+
ax.set_title("Diagramme de Dang Van - École Centrale Lyon",
|
| 142 |
+
fontsize=14, fontweight='bold', pad=20)
|
| 143 |
+
|
| 144 |
+
if show_grid:
|
| 145 |
+
ax.grid(True, linestyle='--', alpha=0.3)
|
| 146 |
+
|
| 147 |
+
ax.legend(loc='best', frameon=True, fancybox=True, shadow=True)
|
| 148 |
+
|
| 149 |
+
# Ajustement des limites
|
| 150 |
+
xlim_min = min(points_uniaxial[:, 0].min(), points_torsion[:, 0].min()) - 10
|
| 151 |
+
xlim_max = max(points_uniaxial[:, 0].max(), points_torsion[:, 0].max()) + 10
|
| 152 |
+
ylim_max = max(points_uniaxial[:, 1].max(), points_torsion[:, 1].max()) + 10
|
| 153 |
+
ax.set_xlim(xlim_min, xlim_max)
|
| 154 |
+
ax.set_ylim(0, ylim_max)
|
| 155 |
+
|
| 156 |
+
# Sauvegarde de la figure pour affichage HTML
|
| 157 |
+
buf = io.BytesIO()
|
| 158 |
+
fig.savefig(buf, format='png', dpi=300, bbox_inches='tight')
|
| 159 |
+
buf.seek(0)
|
| 160 |
+
plot_html = f'<img src="data:image/png;base64,{base64.b64encode(buf.read()).decode()}" style="max-width: 100%; height: auto;">'
|
| 161 |
+
plt.close(fig)
|
| 162 |
+
|
| 163 |
+
# Calcul des statistiques
|
| 164 |
+
stats_uniaxial = len(points_uniaxial)
|
| 165 |
+
stats_torsion = len(points_torsion)
|
| 166 |
+
mean_hydro = np.mean(points_uniaxial[:, 0])
|
| 167 |
+
max_shear = max(points_uniaxial[:, 1].max(), points_torsion[:, 1].max())
|
| 168 |
+
|
| 169 |
+
# Création des DataFrames pour l'export
|
| 170 |
+
df_uniaxial = pd.DataFrame(points_uniaxial, columns=['Pression_hydrostatique', 'Cisaillement_max'])
|
| 171 |
+
df_torsion = pd.DataFrame(points_torsion, columns=['Pression_hydrostatique', 'Cisaillement_max'])
|
| 172 |
+
|
| 173 |
+
# Analyse du critère
|
| 174 |
+
alpha_est = 0.5
|
| 175 |
+
beta_est = points_uniaxial[:, 1].max() + alpha_est * points_uniaxial[:, 0].mean()
|
| 176 |
+
|
| 177 |
+
analysis_text = f"""
|
| 178 |
+
### Analyse du critère de Dang Van
|
| 179 |
+
|
| 180 |
+
Le critère de Dang Van s'exprime sous la forme :
|
| 181 |
+
|
| 182 |
+
τ_a,max + α × p_h ≤ β
|
| 183 |
+
|
| 184 |
+
où :
|
| 185 |
+
- τ_a,max est l'amplitude maximale de cisaillement
|
| 186 |
+
- p_h est la pression hydrostatique
|
| 187 |
+
- α et β sont des constantes matériau
|
| 188 |
+
|
| 189 |
+
**Paramètres estimés :**
|
| 190 |
+
- α ≈ {alpha_est:.3f}
|
| 191 |
+
- β ≈ {beta_est:.1f} MPa
|
| 192 |
+
"""
|
| 193 |
+
|
| 194 |
+
stats_text = f"""
|
| 195 |
+
### 📊 Résultats statistiques
|
| 196 |
+
|
| 197 |
+
**Points uniaxiaux :** {stats_uniaxial} (σ₁={sigma1}MPa)
|
| 198 |
+
**Points torsion :** {stats_torsion} (ω={omega:.2f} rad/s)
|
| 199 |
+
**Pression hydro. moyenne :** {mean_hydro:.1f} MPa (Uniaxial)
|
| 200 |
+
**Cisaillement max :** {max_shear:.1f} MPa
|
| 201 |
+
"""
|
| 202 |
+
|
| 203 |
+
# Retourner les résultats dans le bon format pour Gradio
|
| 204 |
+
return (
|
| 205 |
+
plot_html, # HTML pour l'affichage du graphique
|
| 206 |
+
stats_text, # Texte pour les statistiques
|
| 207 |
+
analysis_text, # Texte pour l'analyse
|
| 208 |
+
df_uniaxial.head(20).to_html(classes='table table-striped'), # HTML tableau uniaxial
|
| 209 |
+
df_torsion.head(20).to_html(classes='table table-striped'), # HTML tableau torsion
|
| 210 |
+
df_uniaxial.to_csv(index=False), # CSV uniaxial pour téléchargement
|
| 211 |
+
df_torsion.to_csv(index=False), # CSV torsion pour téléchargement
|
| 212 |
+
buf.getvalue() # Image pour téléchargement
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
except Exception as e:
|
| 216 |
+
error_msg = f"Erreur lors du calcul : {str(e)}"
|
| 217 |
+
# Retourner une structure vide mais valide en cas d'erreur
|
| 218 |
+
return (
|
| 219 |
+
f"<p style='color: red;'>{error_msg}</p>",
|
| 220 |
+
f"❌ {error_msg}",
|
| 221 |
+
f"❌ {error_msg}",
|
| 222 |
+
f"<p style='color: red;'>{error_msg}</p>",
|
| 223 |
+
f"<p style='color: red;'>{error_msg}</p>",
|
| 224 |
+
"",
|
| 225 |
+
"",
|
| 226 |
+
None
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
# Interface Gradio
|
| 230 |
+
with gr.Blocks(title="Critère de Dang Van - École Centrale Lyon") as demo:
|
| 231 |
+
gr.HTML(create_header())
|
| 232 |
+
|
| 233 |
+
with gr.Row():
|
| 234 |
+
with gr.Column(scale=1):
|
| 235 |
+
gr.Markdown("### 🔧 Paramètres d'étude")
|
| 236 |
+
|
| 237 |
+
sigma1 = gr.Slider(
|
| 238 |
+
minimum=10,
|
| 239 |
+
maximum=200,
|
| 240 |
+
value=100,
|
| 241 |
+
step=5,
|
| 242 |
+
label="Amplitude σ₁ (MPa)",
|
| 243 |
+
info="Amplitude de contrainte en traction-compression"
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
omega = gr.Slider(
|
| 247 |
+
minimum=0.1,
|
| 248 |
+
maximum=10.0,
|
| 249 |
+
value=2*pi,
|
| 250 |
+
step=0.1,
|
| 251 |
+
label="ω (rad/s)",
|
| 252 |
+
info="Fréquence angulaire du chargement"
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
fin = gr.Slider(
|
| 256 |
+
minimum=0.1,
|
| 257 |
+
maximum=2.0,
|
| 258 |
+
value=1.0,
|
| 259 |
+
step=0.1,
|
| 260 |
+
label="Temps final"
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
pasTemps = gr.Slider(
|
| 264 |
+
minimum=0.001,
|
| 265 |
+
maximum=0.1,
|
| 266 |
+
value=0.1,
|
| 267 |
+
step=0.001,
|
| 268 |
+
label="Pas de temps"
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
gr.Markdown("### 📊 Options d'affichage")
|
| 272 |
+
point_size = gr.Slider(10, 100, 30, label="Taille des points")
|
| 273 |
+
show_grid = gr.Checkbox(True, label="Afficher la grille")
|
| 274 |
+
theme = gr.Dropdown(
|
| 275 |
+
["Classique", "Moderne", "Scientifique"],
|
| 276 |
+
value="Classique",
|
| 277 |
+
label="Thème du graphique"
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
calculate_btn = gr.Button(
|
| 281 |
+
"🚀 Lancer le calcul et la visualisation",
|
| 282 |
+
variant="primary",
|
| 283 |
+
size="lg"
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
with gr.Column(scale=2):
|
| 287 |
+
gr.Markdown("### Objectif de l'étude")
|
| 288 |
+
gr.HTML("""
|
| 289 |
+
<div class="centrale-card">
|
| 290 |
+
<p>Cette application permet d'analyser le comportement en fatigue des matériaux selon le critère de Dang Van.
|
| 291 |
+
Le critère permet de prédire l'apparition de fissures de fatigue en considérant simultanément la pression
|
| 292 |
+
hydrostatique et l'amplitude de cisaillement.</p>
|
| 293 |
+
</div>
|
| 294 |
+
""")
|
| 295 |
+
|
| 296 |
+
plot_output = gr.HTML()
|
| 297 |
+
|
| 298 |
+
with gr.Tabs():
|
| 299 |
+
with gr.TabItem("📈 Statistiques"):
|
| 300 |
+
stats_output = gr.Markdown()
|
| 301 |
+
|
| 302 |
+
with gr.TabItem("📄 Analyse"):
|
| 303 |
+
analysis_output = gr.Markdown()
|
| 304 |
+
|
| 305 |
+
with gr.TabItem("💾 Export des données"):
|
| 306 |
+
with gr.Row():
|
| 307 |
+
with gr.Column():
|
| 308 |
+
gr.Markdown("**Données Traction-Compression**")
|
| 309 |
+
uniaxial_table = gr.HTML()
|
| 310 |
+
with gr.Column():
|
| 311 |
+
gr.Markdown("**Données Torsion**")
|
| 312 |
+
torsion_table = gr.HTML()
|
| 313 |
+
|
| 314 |
+
with gr.Row():
|
| 315 |
+
uniaxial_csv = gr.File(label="CSV Traction-Compression")
|
| 316 |
+
torsion_csv = gr.File(label="CSV Torsion")
|
| 317 |
+
plot_download = gr.File(label="Graphique PNG")
|
| 318 |
+
|
| 319 |
+
# Informations
|
| 320 |
+
gr.HTML(create_info_panel())
|
| 321 |
+
|
| 322 |
+
# Footer
|
| 323 |
+
gr.HTML("""
|
| 324 |
+
<div class="footer">
|
| 325 |
+
<p><strong>École Centrale Lyon</strong> | Mécanique des Matériaux | UE: Fatigue et Fissuration</p>
|
| 326 |
+
<p style="font-size: 0.8rem; opacity: 0.8;">
|
| 327 |
+
Rapport technique - © 2026 - Tous droits réservés
|
| 328 |
+
</p>
|
| 329 |
+
</div>
|
| 330 |
+
""")
|
| 331 |
+
|
| 332 |
+
# Gestion des événements
|
| 333 |
+
calculate_btn.click(
|
| 334 |
+
fn=calculate_dang_van,
|
| 335 |
+
inputs=[sigma1, omega, fin, pasTemps, point_size, show_grid, theme],
|
| 336 |
+
outputs=[
|
| 337 |
+
plot_output,
|
| 338 |
+
stats_output,
|
| 339 |
+
analysis_output,
|
| 340 |
+
uniaxial_table,
|
| 341 |
+
torsion_table,
|
| 342 |
+
uniaxial_csv,
|
| 343 |
+
torsion_csv,
|
| 344 |
+
plot_download
|
| 345 |
+
]
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
# Lancement de l'application
|
| 349 |
+
if __name__ == "__main__":
|
| 350 |
+
demo.launch(
|
| 351 |
+
server_name="0.0.0.0",
|
| 352 |
+
server_port=7860,
|
| 353 |
+
share=False,
|
| 354 |
+
css=css
|
| 355 |
+
)
|
app_simple.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import versDV as dv
|
| 5 |
+
import deviatoire as dev
|
| 6 |
+
from math import pi
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import io
|
| 9 |
+
import base64
|
| 10 |
+
|
| 11 |
+
def create_header():
|
| 12 |
+
"""Header simple sans CSS complexe"""
|
| 13 |
+
return """
|
| 14 |
+
<div style="background: linear-gradient(90deg, #D52B1E 0%, #B22222 100%); padding: 2rem; text-align: center; color: white; margin-bottom: 1rem;">
|
| 15 |
+
<h1 style="font-family: Georgia, serif; font-weight: bold; margin: 0;">ÉCOLE CENTRALE LYON</h1>
|
| 16 |
+
<h2 style="font-family: Arial, sans-serif; font-size: 1.2rem; margin: 0.5rem 0 0 0;">Analyse de Fatigue - Critère de Dang Van</h2>
|
| 17 |
+
</div>
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
def calculate_dang_van(sigma1, omega, fin, pasTemps, point_size, show_grid, theme):
|
| 21 |
+
"""Calcul ultra-robuste et simple"""
|
| 22 |
+
try:
|
| 23 |
+
# Calcul des points - version simple
|
| 24 |
+
points_uniaxial = dv.nuage(sigma1, omega, pasTemps, fin)
|
| 25 |
+
points_torsion = dv.nuageOrt(sigma1, omega, pasTemps, fin)
|
| 26 |
+
|
| 27 |
+
# Création du graphique simple
|
| 28 |
+
plt.figure(figsize=(10, 6))
|
| 29 |
+
plt.scatter(points_uniaxial[:, 0], points_uniaxial[:, 1],
|
| 30 |
+
s=point_size, alpha=0.7, label='Traction-Compression')
|
| 31 |
+
plt.scatter(points_torsion[:, 0], points_torsion[:, 1],
|
| 32 |
+
s=point_size, alpha=0.7, label='Torsion')
|
| 33 |
+
|
| 34 |
+
plt.xlabel("Pression hydrostatique (MPa)")
|
| 35 |
+
plt.ylabel("Amplitude de cisaillement max (MPa)")
|
| 36 |
+
plt.title("Diagramme de Dang Van - École Centrale Lyon")
|
| 37 |
+
plt.legend()
|
| 38 |
+
plt.grid(show_grid)
|
| 39 |
+
|
| 40 |
+
# Sauvegarde
|
| 41 |
+
buf = io.BytesIO()
|
| 42 |
+
plt.savefig(buf, format='png', dpi=150, bbox_inches='tight')
|
| 43 |
+
buf.seek(0)
|
| 44 |
+
plot_base64 = base64.b64encode(buf.read()).decode()
|
| 45 |
+
plt.close()
|
| 46 |
+
|
| 47 |
+
# Statistiques simples
|
| 48 |
+
stats_text = f"""
|
| 49 |
+
### 📊 Résultats
|
| 50 |
+
|
| 51 |
+
- **Points uniaxiaux :** {len(points_uniaxial)}
|
| 52 |
+
- **Points torsion :** {len(points_torsion)}
|
| 53 |
+
- **Contrainte σ₁ :** {sigma1} MPa
|
| 54 |
+
- **Fréquence ω :** {omega:.2f} rad/s
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
# Analyse simple
|
| 58 |
+
analysis_text = f"""
|
| 59 |
+
### Analyse du critère de Dang Van
|
| 60 |
+
|
| 61 |
+
Le critère de Dang Van : τ_a,max + α × p_h ≤ β
|
| 62 |
+
|
| 63 |
+
**Paramètres :**
|
| 64 |
+
- α ≈ 0.5
|
| 65 |
+
- β ≈ {points_uniaxial[:, 1].max() + 0.5 * points_uniaxial[:, 0].mean():.1f} MPa
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
# Données pour export
|
| 69 |
+
df_uniaxial = pd.DataFrame(points_uniaxial, columns=['Pression_hydrostatique', 'Cisaillement_max'])
|
| 70 |
+
df_torsion = pd.DataFrame(points_torsion, columns=['Pression_hydrostatique', 'Cisaillement_max'])
|
| 71 |
+
|
| 72 |
+
# Retour simplifié - valeurs brutes pour éviter les erreurs
|
| 73 |
+
return (
|
| 74 |
+
f'<img src="data:image/png;base64,{plot_base64}" style="max-width: 100%;">',
|
| 75 |
+
stats_text,
|
| 76 |
+
analysis_text,
|
| 77 |
+
df_uniaxial.head(10).to_html(),
|
| 78 |
+
df_torsion.head(10).to_html(),
|
| 79 |
+
df_uniaxial.to_csv(index=False),
|
| 80 |
+
df_torsion.to_csv(index=False),
|
| 81 |
+
buf.getvalue()
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
except Exception as e:
|
| 85 |
+
error_message = f"Erreur: {str(e)}"
|
| 86 |
+
return (
|
| 87 |
+
f"<p style='color: red;'>{error_message}</p>",
|
| 88 |
+
f"❌ {error_message}",
|
| 89 |
+
f"❌ {error_message}",
|
| 90 |
+
"<p>Erreur de calcul</p>",
|
| 91 |
+
"<p>Erreur de calcul</p>",
|
| 92 |
+
"error.csv",
|
| 93 |
+
"error.csv",
|
| 94 |
+
None
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
# Création de l'interface Gradio
|
| 98 |
+
with gr.Blocks(title="Dang Van - École Centrale Lyon") as demo:
|
| 99 |
+
gr.HTML(create_header())
|
| 100 |
+
|
| 101 |
+
with gr.Row():
|
| 102 |
+
with gr.Column(scale=1):
|
| 103 |
+
gr.Markdown("### 🔧 Paramètres")
|
| 104 |
+
|
| 105 |
+
sigma1 = gr.Slider(10, 200, 100, step=5, label="Amplitude σ₁ (MPa)")
|
| 106 |
+
omega = gr.Slider(0.1, 10.0, float(2*pi), step=0.1, label="ω (rad/s)")
|
| 107 |
+
fin = gr.Slider(0.1, 2.0, 1.0, step=0.1, label="Temps final")
|
| 108 |
+
pasTemps = gr.Slider(0.001, 0.1, 0.1, step=0.001, label="Pas de temps")
|
| 109 |
+
point_size = gr.Slider(10, 100, 30, label="Taille des points")
|
| 110 |
+
show_grid = gr.Checkbox(True, label="Afficher la grille")
|
| 111 |
+
|
| 112 |
+
btn = gr.Button("🚀 Lancer la simulation", variant="primary", size="lg")
|
| 113 |
+
|
| 114 |
+
with gr.Column(scale=2):
|
| 115 |
+
gr.Markdown("### 📊 Résultats")
|
| 116 |
+
|
| 117 |
+
plot_output = gr.HTML()
|
| 118 |
+
|
| 119 |
+
with gr.Tabs():
|
| 120 |
+
with gr.TabItem("📈 Statistiques"):
|
| 121 |
+
stats_output = gr.Markdown()
|
| 122 |
+
|
| 123 |
+
with gr.TabItem("📄 Analyse"):
|
| 124 |
+
analysis_output = gr.Markdown()
|
| 125 |
+
|
| 126 |
+
with gr.TabItem("💾 Données"):
|
| 127 |
+
with gr.Row():
|
| 128 |
+
uniaxial_table = gr.HTML()
|
| 129 |
+
torsion_table = gr.HTML()
|
| 130 |
+
|
| 131 |
+
with gr.Row():
|
| 132 |
+
uniaxial_file = gr.File(label="CSV Traction-Compression")
|
| 133 |
+
torsion_file = gr.File(label="CSV Torsion")
|
| 134 |
+
plot_file = gr.File(label="Graphique PNG")
|
| 135 |
+
|
| 136 |
+
# Informations
|
| 137 |
+
gr.HTML("""
|
| 138 |
+
<div style="background: #333; color: white; padding: 1rem; text-align: center; margin-top: 2rem;">
|
| 139 |
+
<p><strong>École Centrale Lyon</strong> | Mécanique des Matériaux | UE: Fatigue et Fissuration</p>
|
| 140 |
+
<p style="font-size: 0.8rem;">© 2026 - Projet de recherche et innovation</p>
|
| 141 |
+
</div>
|
| 142 |
+
""")
|
| 143 |
+
|
| 144 |
+
# Événement
|
| 145 |
+
btn.click(
|
| 146 |
+
fn=calculate_dang_van,
|
| 147 |
+
inputs=[sigma1, omega, fin, pasTemps, point_size, show_grid, gr.Textbox(value="Classique")],
|
| 148 |
+
outputs=[plot_output, stats_output, analysis_output, uniaxial_table, torsion_table, uniaxial_file, torsion_file, plot_file]
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Lancement
|
| 152 |
+
if __name__ == "__main__":
|
| 153 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|