Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,11 @@ from apdl_generator.apdl_plate import generate_plate_apdl
|
|
| 3 |
from apdl_generator.apdl_beam import generate_beam_apdl
|
| 4 |
from simulators.python_simulation import run_python_simulation
|
| 5 |
from visualization import visualize_results, visualize_end_product
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
def simulation_workflow(tool_type, use_case, include_hole, include_force, include_load, thickness, length, width, hole_diameter, force, load, elastic_modulus):
|
| 9 |
"""
|
| 10 |
-
Main simulation workflow
|
| 11 |
"""
|
| 12 |
-
|
| 13 |
# Handle optional parameters
|
| 14 |
force = force if include_force else 0
|
| 15 |
load = load if include_load else 0
|
|
@@ -42,14 +40,54 @@ def simulation_workflow(tool_type, use_case, include_hole, include_force, includ
|
|
| 42 |
# Generate end-product visualization
|
| 43 |
product_path = visualize_end_product(use_case, length, width, thickness, deformation)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from apdl_generator.apdl_beam import generate_beam_apdl
|
| 4 |
from simulators.python_simulation import run_python_simulation
|
| 5 |
from visualization import visualize_results, visualize_end_product
|
|
|
|
| 6 |
|
| 7 |
def simulation_workflow(tool_type, use_case, include_hole, include_force, include_load, thickness, length, width, hole_diameter, force, load, elastic_modulus):
|
| 8 |
"""
|
| 9 |
+
Main simulation workflow.
|
| 10 |
"""
|
|
|
|
| 11 |
# Handle optional parameters
|
| 12 |
force = force if include_force else 0
|
| 13 |
load = load if include_load else 0
|
|
|
|
| 40 |
# Generate end-product visualization
|
| 41 |
product_path = visualize_end_product(use_case, length, width, thickness, deformation)
|
| 42 |
|
| 43 |
+
return (
|
| 44 |
+
f"{tool_type} Simulation\nStress: {stress:.2f} MPa\nDeformation: {deformation:.6f} mm{deformation_note}",
|
| 45 |
+
graph_path,
|
| 46 |
+
product_path,
|
| 47 |
+
apdl_program
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Gradio interface setup
|
| 51 |
+
with gr.Blocks() as interface:
|
| 52 |
+
gr.Markdown("# Punch and Die Simulation Tool")
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
tool_type = gr.Radio(["Punch", "Die"], label="Select Tool Type")
|
| 56 |
+
use_case = gr.Radio(["plate", "beam"], label="Select Use Case")
|
| 57 |
+
|
| 58 |
+
with gr.Row():
|
| 59 |
+
include_hole = gr.Checkbox(label="Include Hole for Plate Simulation")
|
| 60 |
+
include_force = gr.Checkbox(label="Include Force")
|
| 61 |
+
include_load = gr.Checkbox(label="Include Load")
|
| 62 |
+
|
| 63 |
+
with gr.Row():
|
| 64 |
+
thickness = gr.Slider(10, 50, step=1, label="Thickness (mm)")
|
| 65 |
+
length = gr.Slider(100, 500, step=10, label="Length (mm)")
|
| 66 |
+
width = gr.Slider(50, 200, step=10, label="Width (mm)")
|
| 67 |
+
|
| 68 |
+
with gr.Row():
|
| 69 |
+
hole_diameter = gr.Slider(5, 25, step=1, label="Hole Diameter (mm)")
|
| 70 |
+
force = gr.Slider(1000, 10000, step=500, label="Force (N)")
|
| 71 |
+
load = gr.Slider(1000, 20000, step=1000, label="Load (N)")
|
| 72 |
+
elastic_modulus = gr.Slider(5e10, 3e11, step=1e10, label="Elastic Modulus (Pa)")
|
| 73 |
+
|
| 74 |
+
submit_button = gr.Button("Run Simulation")
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
result_text = gr.Textbox(label="Simulation Results")
|
| 78 |
+
result_graph = gr.Image(label="2D Simulation Visualization")
|
| 79 |
+
result_product = gr.Image(label="End Product Visualization")
|
| 80 |
+
apdl_output = gr.Code(language="python", label="Generated APDL Program")
|
| 81 |
+
|
| 82 |
+
# Link the button to the simulation function
|
| 83 |
+
submit_button.click(
|
| 84 |
+
simulation_workflow,
|
| 85 |
+
inputs=[
|
| 86 |
+
tool_type, use_case, include_hole, include_force, include_load,
|
| 87 |
+
thickness, length, width, hole_diameter, force, load, elastic_modulus
|
| 88 |
+
],
|
| 89 |
+
outputs=[result_text, result_graph, result_product, apdl_output]
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# Launch interface
|
| 93 |
+
interface.launch()
|