Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,34 @@ import gradio as gr
|
|
| 2 |
from ai_models import train_models, load_models
|
| 3 |
from ansys_simulation import run_ansys_simulation
|
| 4 |
from visualization import generate_graph
|
|
|
|
| 5 |
|
| 6 |
# Load AI models
|
| 7 |
stress_model, deformation_model, pass_fail_model = load_models()
|
| 8 |
|
| 9 |
def ai_and_simulation_workflow(thickness, hole_diameter, force):
|
| 10 |
# AI Pre-Screening
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if pre_screen == 0:
|
| 13 |
return "AI predicts failure. Adjust parameters.", None
|
| 14 |
|
| 15 |
# ANSYS Simulation
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Generate Visualization
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
return f"Pass: Stress={max_stress} Pa, Deformation={max_deformation} mm", graph_path
|
| 22 |
|
|
|
|
| 2 |
from ai_models import train_models, load_models
|
| 3 |
from ansys_simulation import run_ansys_simulation
|
| 4 |
from visualization import generate_graph
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# Load AI models
|
| 8 |
stress_model, deformation_model, pass_fail_model = load_models()
|
| 9 |
|
| 10 |
def ai_and_simulation_workflow(thickness, hole_diameter, force):
|
| 11 |
# AI Pre-Screening
|
| 12 |
+
try:
|
| 13 |
+
pre_screen = pass_fail_model.predict([[thickness, hole_diameter, force]])[0]
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error with AI model prediction: {str(e)}", None
|
| 16 |
+
|
| 17 |
if pre_screen == 0:
|
| 18 |
return "AI predicts failure. Adjust parameters.", None
|
| 19 |
|
| 20 |
# ANSYS Simulation
|
| 21 |
+
try:
|
| 22 |
+
max_stress, max_deformation = run_ansys_simulation(thickness, hole_diameter, force)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Error with ANSYS simulation: {str(e)}", None
|
| 25 |
|
| 26 |
# Generate Visualization
|
| 27 |
+
try:
|
| 28 |
+
graph_path = generate_graph(thickness, hole_diameter, force, max_stress, max_deformation)
|
| 29 |
+
if not os.path.exists(graph_path):
|
| 30 |
+
return f"Error: Graph path '{graph_path}' does not exist.", None
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error with graph generation: {str(e)}", None
|
| 33 |
|
| 34 |
return f"Pass: Stress={max_stress} Pa, Deformation={max_deformation} mm", graph_path
|
| 35 |
|