Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,14 @@
|
|
| 1 |
from ansys.mapdl.core import launch_mapdl
|
| 2 |
-
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Function to generate
|
| 6 |
-
def
|
| 7 |
try:
|
| 8 |
-
if length <= 0 or width <= 0 or thickness <= 0
|
| 9 |
-
return "Dimensions
|
| 10 |
|
| 11 |
-
# Launch ANSYS MAPDL session
|
| 12 |
-
mapdl = launch_mapdl(
|
| 13 |
mapdl.clear() # Clear any previous settings
|
| 14 |
|
| 15 |
# Preprocessing
|
|
@@ -17,56 +16,40 @@ def generate_progressive_die_ANSYS(length, width, thickness, num_stations, punch
|
|
| 17 |
|
| 18 |
# Die shape logic
|
| 19 |
if die_shape == "Rectangle":
|
| 20 |
-
mapdl.block(0, length, 0, width, 0, thickness) # Create a rectangular block
|
| 21 |
elif die_shape == "Circle":
|
| 22 |
-
mapdl.cylind(0, 0, width / 2, 0, thickness) # Create a cylindrical block
|
| 23 |
-
|
| 24 |
-
# Create punch shapes for each station
|
| 25 |
-
punch_spacing = length / (num_stations + 1) # Space punches evenly along length
|
| 26 |
-
|
| 27 |
-
for station in range(1, num_stations + 1):
|
| 28 |
-
punch_center_x = station * punch_spacing
|
| 29 |
-
punch_center_y = width / 2 # Center the punch along the width
|
| 30 |
-
|
| 31 |
-
# Create cylindrical punches (holes in the die)
|
| 32 |
-
mapdl.cylind(punch_center_x, punch_center_y, punch_diameter / 2, 0, punch_depth)
|
| 33 |
|
| 34 |
# Save the geometry as a STEP file
|
| 35 |
-
filename = f"
|
| 36 |
-
mapdl.save_as(filename)
|
| 37 |
-
mapdl.exit() #
|
| 38 |
-
|
| 39 |
-
# Return success message with station info
|
| 40 |
-
return f"Progressive Die design saved successfully as {filename}. The die has {num_stations} punch stations."
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
-
return f"Error generating
|
| 44 |
|
| 45 |
-
# Gradio interface
|
| 46 |
-
def progressive_die_interface(length, width, thickness,
|
| 47 |
-
return
|
| 48 |
|
| 49 |
# Create the Gradio Interface
|
| 50 |
with gr.Blocks() as app:
|
| 51 |
-
gr.Markdown("## Progressive Die Design with ANSYS
|
| 52 |
-
gr.Markdown("
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle"], value="Rectangle")
|
| 65 |
-
die_output = gr.Textbox(label="Output", interactive=False)
|
| 66 |
-
die_button = gr.Button("Generate Die")
|
| 67 |
-
die_button.click(progressive_die_interface, inputs=[length, width, thickness, num_stations, punch_diameter, punch_depth, die_shape], outputs=die_output)
|
| 68 |
|
| 69 |
# Launch the app
|
| 70 |
app.launch()
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 1 |
from ansys.mapdl.core import launch_mapdl
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Function to generate die design using ANSYS MAPDL
|
| 5 |
+
def generate_die_ANSYS(length, width, thickness, die_shape):
|
| 6 |
try:
|
| 7 |
+
if length <= 0 or width <= 0 or thickness <= 0:
|
| 8 |
+
return "Dimensions must be greater than zero."
|
| 9 |
|
| 10 |
+
# Launch ANSYS MAPDL session (without interactive argument)
|
| 11 |
+
mapdl = launch_mapdl() # Start MAPDL session
|
| 12 |
mapdl.clear() # Clear any previous settings
|
| 13 |
|
| 14 |
# Preprocessing
|
|
|
|
| 16 |
|
| 17 |
# Die shape logic
|
| 18 |
if die_shape == "Rectangle":
|
| 19 |
+
mapdl.block(0, length, 0, width, 0, thickness) # Create a rectangular block
|
| 20 |
elif die_shape == "Circle":
|
| 21 |
+
mapdl.cylind(0, 0, width / 2, 0, thickness) # Create a cylindrical block
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Save the geometry as a STEP file
|
| 24 |
+
filename = f"generated_die_{die_shape}_{length}x{width}x{thickness}.step"
|
| 25 |
+
mapdl.save_as(filename) # Save the design as STEP file
|
| 26 |
+
mapdl.exit() # Exit the MAPDL session
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Return success message with the file path
|
| 29 |
+
return f"Die design saved successfully as {filename}. You can download the file."
|
| 30 |
+
|
| 31 |
except Exception as e:
|
| 32 |
+
return f"Error generating die design: {str(e)}"
|
| 33 |
|
| 34 |
+
# Gradio interface functions for Progressive Die Design
|
| 35 |
+
def progressive_die_interface(length, width, thickness, die_shape):
|
| 36 |
+
return generate_die_ANSYS(length, width, thickness, die_shape)
|
| 37 |
|
| 38 |
# Create the Gradio Interface
|
| 39 |
with gr.Blocks() as app:
|
| 40 |
+
gr.Markdown("## Progressive Die Design Tool with ANSYS")
|
| 41 |
+
gr.Markdown("Select the dimensions and shape for the progressive die below:")
|
| 42 |
+
|
| 43 |
+
# Tab for Progressive Die Design
|
| 44 |
+
with gr.Tab("Progressive Die Design"):
|
| 45 |
+
gr.Markdown("### Enter Dimensions and Shape for Progressive Die")
|
| 46 |
+
length = gr.Number(label="Length (mm)", value=100)
|
| 47 |
+
width = gr.Number(label="Width (mm)", value=50)
|
| 48 |
+
thickness = gr.Number(label="Thickness (mm)", value=10)
|
| 49 |
+
die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle"], value="Rectangle")
|
| 50 |
+
die_output = gr.Textbox(label="Output", interactive=False)
|
| 51 |
+
die_button = gr.Button("Generate Die")
|
| 52 |
+
die_button.click(progressive_die_interface, inputs=[length, width, thickness, die_shape], outputs=die_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# Launch the app
|
| 55 |
app.launch()
|
|
|
|
|
|