jithenderchoudary commited on
Commit
0e54e20
·
verified ·
1 Parent(s): 551d738

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -62
app.py CHANGED
@@ -1,13 +1,12 @@
1
  import pyvista as pv
2
  import streamlit as st
3
- from streamlit_pyvista import st_pyvista
4
- import numpy as np
5
- import pyvista as pv
6
- import streamlit as st
7
 
8
- # Define parameters for the punch and die
9
- length, width, height = 50, 30, 10
10
- inner_width, inner_height, die_thickness = 40, 20, 15
 
 
 
11
 
12
  # Function to create punch and die geometry
13
  def create_geometry(length, width, height, inner_width, inner_height, thickness):
@@ -17,45 +16,6 @@ def create_geometry(length, width, height, inner_width, inner_height, thickness)
17
  -thickness, 0))
18
  return punch, die
19
 
20
- # Generate punch and die models
21
- punch, die = create_geometry(length, width, height, inner_width, inner_height, die_thickness)
22
-
23
-
24
- # Save the visualization as an image
25
- image_path = "visualization.png"
26
- plotter.screenshot(image_path)
27
-
28
- # Display the image in Streamlit
29
- st.title("Punch and Die Visualization")
30
- st.image(image_path, caption="3D Visualization of Punch and Die", use_column_width=True)
31
-
32
-
33
- # Generate the punch and die
34
- punch, die = create_geometry(length, width, height, inner_width, inner_height, die_thickness)
35
-
36
- # Create and save plot
37
- plotter = pv.Plotter(off_screen=True)
38
- plotter.add_mesh(punch, color="blue", opacity=0.5, label="Punch")
39
- plotter.add_mesh(die, color="red", opacity=0.5, label="Die")
40
- plotter.add_axes()
41
- plotter.show_bounds()
42
- plotter.view_xy()
43
-
44
- # Save the plot as an image
45
- plot_path = "visualization.png"
46
- plotter.screenshot(plot_path)
47
-
48
- # Display in Streamlit
49
- st.image(plot_path, caption="Punch and Die Visualization")
50
-
51
-
52
- # Material properties (dummy data)
53
- materials = {
54
- "Steel": {"Density": 7850, "Yield Strength": 250},
55
- "Aluminum": {"Density": 2700, "Yield Strength": 50},
56
- "Brass": {"Density": 8500, "Yield Strength": 200},
57
- }
58
-
59
  # Streamlit App
60
  st.title("Interactive Punch and Die Design Tool")
61
  st.sidebar.header("Input Parameters")
@@ -83,28 +43,24 @@ st.sidebar.subheader("Material Properties")
83
  st.sidebar.write(f"Density: {materials[material]['Density']} kg/m³")
84
  st.sidebar.write(f"Yield Strength: {materials[material]['Yield Strength']} MPa")
85
 
86
- # Function to create punch and die geometry
87
- def create_geometry(length, width, height, inner_width, inner_height, thickness):
88
- punch = pv.Box(bounds=(0, length, 0, width, 0, height))
89
- die = pv.Box(bounds=(-inner_width / 2, inner_width / 2,
90
- -inner_height / 2, inner_height / 2,
91
- -thickness, 0))
92
- return punch, die
93
-
94
- # Generate models
95
  punch, die = create_geometry(length, width, height, inner_width, inner_height, die_thickness)
96
 
97
- # Display 3D Visualization
98
  st.subheader("3D Visualization of Punch and Die")
99
- plotter = pv.Plotter()
100
  plotter.add_mesh(punch, color="blue", opacity=0.5, label="Punch")
101
  plotter.add_mesh(die, color="red", opacity=0.5, label="Die")
102
  plotter.add_axes()
103
  plotter.show_bounds()
104
  plotter.view_xy()
105
 
106
- # Show the visualization in Streamlit
107
- st_pyvista(plotter)
 
 
 
 
108
 
109
  # Generate APDL Script
110
  st.subheader("Generated APDL Script")
@@ -126,11 +82,11 @@ SOLVE
126
  /POST1
127
  """
128
 
 
129
  st.code(apdl_script)
130
-
131
- # Option to download APDL Script
132
  st.download_button("Download APDL Script", apdl_script, "generated_apdl_script.txt")
133
 
134
- # Placeholder for future validation results
135
  st.subheader("Validation Feedback")
136
  st.write("Validation results and stress maps will be shown here.")
 
 
1
  import pyvista as pv
2
  import streamlit as st
 
 
 
 
3
 
4
+ # Material properties (dummy data)
5
+ materials = {
6
+ "Steel": {"Density": 7850, "Yield Strength": 250},
7
+ "Aluminum": {"Density": 2700, "Yield Strength": 50},
8
+ "Brass": {"Density": 8500, "Yield Strength": 200},
9
+ }
10
 
11
  # Function to create punch and die geometry
12
  def create_geometry(length, width, height, inner_width, inner_height, thickness):
 
16
  -thickness, 0))
17
  return punch, die
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Streamlit App
20
  st.title("Interactive Punch and Die Design Tool")
21
  st.sidebar.header("Input Parameters")
 
43
  st.sidebar.write(f"Density: {materials[material]['Density']} kg/m³")
44
  st.sidebar.write(f"Yield Strength: {materials[material]['Yield Strength']} MPa")
45
 
46
+ # Generate Punch and Die Models
 
 
 
 
 
 
 
 
47
  punch, die = create_geometry(length, width, height, inner_width, inner_height, die_thickness)
48
 
49
+ # 3D Visualization
50
  st.subheader("3D Visualization of Punch and Die")
51
+ plotter = pv.Plotter(off_screen=True) # Use off_screen for static visualization
52
  plotter.add_mesh(punch, color="blue", opacity=0.5, label="Punch")
53
  plotter.add_mesh(die, color="red", opacity=0.5, label="Die")
54
  plotter.add_axes()
55
  plotter.show_bounds()
56
  plotter.view_xy()
57
 
58
+ # Save the visualization as an image
59
+ image_path = "visualization.png"
60
+ plotter.screenshot(image_path)
61
+
62
+ # Display the image in Streamlit
63
+ st.image(image_path, caption="3D Visualization of Punch and Die", use_column_width=True)
64
 
65
  # Generate APDL Script
66
  st.subheader("Generated APDL Script")
 
82
  /POST1
83
  """
84
 
85
+ # Display and Download APDL Script
86
  st.code(apdl_script)
 
 
87
  st.download_button("Download APDL Script", apdl_script, "generated_apdl_script.txt")
88
 
89
+ # Placeholder for Validation Results
90
  st.subheader("Validation Feedback")
91
  st.write("Validation results and stress maps will be shown here.")
92
+