karthikmn commited on
Commit
37e9ef0
·
verified ·
1 Parent(s): e66df73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -38
app.py CHANGED
@@ -1,47 +1,30 @@
 
 
 
1
  import gradio as gr
2
- import FreeCAD, Part
3
- from ansys.mapdl.core import launch_mapdl
4
 
5
- def generate_and_simulate(part_name, length, width, height, material_property):
6
- # Step 1: Create CAD Model with FreeCAD
7
- try:
8
- doc = FreeCAD.newDocument(part_name)
9
- box = Part.makeBox(length, width, height)
10
- Part.show(box)
11
- step_file = f"{part_name}.step"
12
- box.exportStep(step_file)
13
- except Exception as e:
14
- return f"Error in FreeCAD CAD generation: {e}"
15
 
16
- # Step 2: Simulate in ANSYS
17
- try:
18
- mapdl = launch_mapdl()
19
- mapdl.prep7()
20
- mapdl.et(1, "SOLID186")
21
- mapdl.mp("EX", 1, material_property) # Elastic modulus
22
- mapdl.input(step_file)
23
- mapdl.vmesh("ALL")
24
- mapdl.solve()
25
- displacement = mapdl.post_processing.nodal_displacement()
26
- mapdl.exit()
27
- except Exception as e:
28
- return f"Error in ANSYS simulation: {e}"
29
 
30
- return f"Simulation completed! Displacement results: {displacement}"
 
31
 
32
- # Gradio Interface
33
- iface = gr.Interface(
34
- fn=generate_and_simulate,
 
35
  inputs=[
36
- gr.Textbox(label="Part Name", placeholder="Enter the part name"),
37
- gr.Number(label="Length (mm)"),
38
- gr.Number(label="Width (mm)"),
39
- gr.Number(label="Height (mm)"),
40
- gr.Number(label="Material Elastic Modulus (Pa)"),
41
  ],
42
- outputs="text",
43
- title="FreeCAD and ANSYS Automation",
44
- description="Generate CAD models and perform ANSYS simulations automatically!"
45
  )
46
 
47
- iface.launch()
 
 
1
+ from utils.cad_utils import generate_cad_model
2
+ from utils.simulation_utils import run_simulation
3
+ from utils.gcode_utils import generate_gcode
4
  import gradio as gr
 
 
5
 
6
+ def automate_workflow(dimensions, material, tolerances):
7
+ # Step 1: Generate CAD model
8
+ cad_file = generate_cad_model(dimensions)
 
 
 
 
 
 
 
9
 
10
+ # Step 2: Run simulation
11
+ simulation_results = run_simulation(cad_file)
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ # Step 3: Generate G-Code
14
+ gcode_file = generate_gcode(cad_file)
15
 
16
+ return f"Simulation Results: {simulation_results}", gcode_file
17
+
18
+ interface = gr.Interface(
19
+ fn=automate_workflow,
20
  inputs=[
21
+ gr.Textbox(label="Dimensions (e.g., 100x50x30 mm)"),
22
+ gr.Textbox(label="Material (e.g., Steel)"),
23
+ gr.Textbox(label="Tolerances (e.g., ±0.05 mm)")
 
 
24
  ],
25
+ outputs=["text", "file"],
26
+ title="End-to-End Automation Workflow"
 
27
  )
28
 
29
+ if __name__ == "__main__":
30
+ interface.launch()