jithenderchoudary commited on
Commit
8bcce63
·
verified ·
1 Parent(s): 929ef30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
- import pyvista as pv
5
- import cadquery as cq
6
 
7
  # Function for Stress Analysis
8
  def stress_analysis(force, die_width, die_height, material_strength):
@@ -34,27 +33,19 @@ def stress_analysis(force, die_width, die_height, material_strength):
34
  except Exception as e:
35
  return f"Error in stress analysis: {str(e)}"
36
 
37
- # Function for 3D Visualization
38
  def visualize_die(length, width, thickness):
39
  try:
40
- # Create a basic die shape using CadQuery
41
- plate = cq.Workplane("XY").box(length, width, thickness)
42
- punch = cq.Workplane("XY").rect(10, 10).extrude(5).translate((length / 4, width / 4, thickness / 2))
43
- die = plate.cut(punch)
 
 
44
 
45
- # Export to STL for visualization
46
- stl_file = "/tmp/progressive_die.stl"
47
- cq.exporters.exportShape(die.val(), "STL", stl_file)
48
-
49
- # Visualize with PyVista
50
- mesh = pv.read(stl_file)
51
- plotter = pv.Plotter(off_screen=True)
52
- plotter.add_mesh(mesh, color="blue")
53
-
54
- # Save the 3D visualization as a PNG
55
  screenshot = "/tmp/progressive_die_visualization.png"
56
- plotter.screenshot(screenshot)
57
- plotter.close()
58
 
59
  return screenshot # Return the screenshot path
60
  except Exception as e:
 
1
  import gradio as gr
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
+ import trimesh
 
5
 
6
  # Function for Stress Analysis
7
  def stress_analysis(force, die_width, die_height, material_strength):
 
33
  except Exception as e:
34
  return f"Error in stress analysis: {str(e)}"
35
 
36
+ # Function for 3D Visualization with Trimesh
37
  def visualize_die(length, width, thickness):
38
  try:
39
+ # Create a basic die shape using Trimesh
40
+ box = trimesh.creation.box(extents=(length, width, thickness))
41
+
42
+ # Save the 3D model as a file
43
+ stl_path = "/tmp/progressive_die.stl"
44
+ box.export(stl_path)
45
 
46
+ # Convert the STL file to a PNG image
 
 
 
 
 
 
 
 
 
47
  screenshot = "/tmp/progressive_die_visualization.png"
48
+ box.show()
 
49
 
50
  return screenshot # Return the screenshot path
51
  except Exception as e: