Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,37 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
from OCC.Core.BRepTools import breptools_Write
|
| 5 |
-
from OCC.Extend.DataExchange import write_stl_file
|
| 6 |
from ansys.mapdl.core import launch_mapdl
|
| 7 |
|
| 8 |
|
| 9 |
-
def
|
| 10 |
"""
|
| 11 |
-
Load
|
| 12 |
Parameters:
|
| 13 |
step_file_path: Path to the uploaded STEP file.
|
| 14 |
Returns:
|
| 15 |
STL file path, dimensions (length, width, height).
|
| 16 |
"""
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
status = step_reader.ReadFile(step_file_path)
|
| 20 |
-
if status != 1:
|
| 21 |
-
raise ValueError("Failed to load the STEP file.")
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Save the model as an STL file
|
| 28 |
stl_file_path = "/tmp/model.stl"
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Calculate dimensions (bounding box)
|
| 32 |
-
bbox = shape.BoundingBox()
|
| 33 |
-
length = bbox.XMax() - bbox.XMin()
|
| 34 |
-
width = bbox.YMax() - bbox.YMin()
|
| 35 |
-
height = bbox.ZMax() - bbox.ZMin()
|
| 36 |
|
| 37 |
return stl_file_path, length, width, height
|
| 38 |
|
| 39 |
|
| 40 |
def generate_apdl_script(length, width, height):
|
| 41 |
"""
|
| 42 |
-
Generate
|
| 43 |
Parameters:
|
| 44 |
length: Length of the model.
|
| 45 |
width: Width of the model.
|
|
@@ -94,16 +86,16 @@ def run_simulation(apdl_script_path):
|
|
| 94 |
return stress_plot, displacement_plot
|
| 95 |
|
| 96 |
|
| 97 |
-
def
|
| 98 |
"""
|
| 99 |
Complete workflow for STEP file: Load -> Generate APDL -> Simulate.
|
| 100 |
Parameters:
|
| 101 |
-
|
| 102 |
Returns:
|
| 103 |
STL file, APDL script, stress plot, displacement plot.
|
| 104 |
"""
|
| 105 |
# Extract geometry from the STEP file
|
| 106 |
-
stl_file, length, width, height =
|
| 107 |
|
| 108 |
# Generate APDL script
|
| 109 |
apdl_script = generate_apdl_script(length, width, height)
|
|
@@ -116,7 +108,7 @@ def process_step_file(step_file):
|
|
| 116 |
|
| 117 |
# Gradio Interface
|
| 118 |
app = gr.Interface(
|
| 119 |
-
fn=
|
| 120 |
inputs=gr.File(label="Upload STEP File"),
|
| 121 |
outputs=[
|
| 122 |
gr.File(label="Download STL File"),
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
import gmsh
|
|
|
|
|
|
|
| 4 |
from ansys.mapdl.core import launch_mapdl
|
| 5 |
|
| 6 |
|
| 7 |
+
def process_step_file(step_file_path):
|
| 8 |
"""
|
| 9 |
+
Load STEP file using GMSH and extract geometry.
|
| 10 |
Parameters:
|
| 11 |
step_file_path: Path to the uploaded STEP file.
|
| 12 |
Returns:
|
| 13 |
STL file path, dimensions (length, width, height).
|
| 14 |
"""
|
| 15 |
+
gmsh.initialize()
|
| 16 |
+
gmsh.open(step_file_path)
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Extract bounding box dimensions
|
| 19 |
+
_, bbox_min, bbox_max = gmsh.model.getBoundingBox(0, 0)
|
| 20 |
+
length = bbox_max[0] - bbox_min[0]
|
| 21 |
+
width = bbox_max[1] - bbox_min[1]
|
| 22 |
+
height = bbox_max[2] - bbox_min[2]
|
| 23 |
|
| 24 |
# Save the model as an STL file
|
| 25 |
stl_file_path = "/tmp/model.stl"
|
| 26 |
+
gmsh.write(stl_file_path)
|
| 27 |
+
gmsh.finalize()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
return stl_file_path, length, width, height
|
| 30 |
|
| 31 |
|
| 32 |
def generate_apdl_script(length, width, height):
|
| 33 |
"""
|
| 34 |
+
Generate APDL script based on dimensions.
|
| 35 |
Parameters:
|
| 36 |
length: Length of the model.
|
| 37 |
width: Width of the model.
|
|
|
|
| 86 |
return stress_plot, displacement_plot
|
| 87 |
|
| 88 |
|
| 89 |
+
def process_cad_file(cad_file):
|
| 90 |
"""
|
| 91 |
Complete workflow for STEP file: Load -> Generate APDL -> Simulate.
|
| 92 |
Parameters:
|
| 93 |
+
cad_file: Uploaded STEP file.
|
| 94 |
Returns:
|
| 95 |
STL file, APDL script, stress plot, displacement plot.
|
| 96 |
"""
|
| 97 |
# Extract geometry from the STEP file
|
| 98 |
+
stl_file, length, width, height = process_step_file(cad_file.name)
|
| 99 |
|
| 100 |
# Generate APDL script
|
| 101 |
apdl_script = generate_apdl_script(length, width, height)
|
|
|
|
| 108 |
|
| 109 |
# Gradio Interface
|
| 110 |
app = gr.Interface(
|
| 111 |
+
fn=process_cad_file,
|
| 112 |
inputs=gr.File(label="Upload STEP File"),
|
| 113 |
outputs=[
|
| 114 |
gr.File(label="Download STL File"),
|