File size: 1,914 Bytes
756df85
595cd05
756df85
 
595cd05
0f64d43
595cd05
 
 
 
 
 
0f64d43
 
 
 
 
595cd05
 
756df85
595cd05
0f64d43
 
 
 
595cd05
 
0f64d43
 
 
 
 
 
595cd05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# app.py
import gradio as gr
from ai_models import load_models
from ansys_simulation import run_ansys_simulation  # Import this function only once
from visualization import generate_graph
import os

# Load AI models
stress_model, deformation_model, pass_fail_model = load_models()

def ai_and_simulation_workflow(thickness, hole_diameter, force):
    # AI Pre-Screening
    try:
        pre_screen = pass_fail_model.predict([[thickness, hole_diameter, force]])[0]
    except Exception as e:
        return f"Error with AI model prediction: {str(e)}", None

    if pre_screen == 0:
        return "AI predicts failure. Adjust parameters.", None
     
    # ANSYS Simulation
    try:
        max_stress, max_deformation = run_ansys_simulation(thickness, hole_diameter, force)
    except Exception as e:
        return f"Error with ANSYS simulation: {str(e)}", None

    # Generate Visualization
    try:
        graph_path = generate_graph(thickness, hole_diameter, force, max_stress, max_deformation)
        if not os.path.exists(graph_path):
            return f"Error: Graph path '{graph_path}' does not exist.", None
    except Exception as e:
        return f"Error with graph generation: {str(e)}", None

    return f"Pass: Stress={max_stress} Pa, Deformation={max_deformation} mm", graph_path

# Gradio UI
interface = gr.Interface(
    fn=ai_and_simulation_workflow,
    inputs=[
        gr.Slider(10, 50, step=1, label="Thickness (mm)"),
        gr.Slider(5, 25, step=1, label="Hole Diameter (mm)"),
        gr.Slider(1000, 15000, step=500, label="Force (N)")
    ],
    outputs=[
        gr.Textbox(label="Simulation Status"),
        gr.Image(label="Dynamic Results Visualization")
    ],
    title="AI-Driven ANSYS Design Validator",
    description="Dynamic tool for optimizing and validating press tool designs.",
    theme="default",
    live=True
)

if __name__ == "__main__":
    interface.launch()