karthikmn commited on
Commit
542982b
·
verified ·
1 Parent(s): 4f8876d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -48
app.py CHANGED
@@ -1,57 +1,23 @@
1
- import os
2
  import gradio as gr
 
3
  from utils.ansys_utils import run_simulation
4
-
5
- def generate_gcode(cad_file):
6
- """
7
- Generates a simple G-Code file for a square path based on the CAD file.
8
- Returns the file path of the generated G-Code file.
9
- """
10
- try:
11
- # Ensure the output directory exists
12
- output_dir = "/mnt/data/"
13
- os.makedirs(output_dir, exist_ok=True)
14
-
15
- # Define the G-Code content
16
- gcode_content = """
17
- G21 ; Set units to millimeters
18
- G17 ; Select XY plane
19
- G90 ; Absolute positioning
20
- G1 F1500 ; Set feed rate
21
-
22
- G0 Z5 ; Raise Z-axis to safe height
23
- G0 X0 Y0 ; Move to start position
24
- G1 Z-1 F300 ; Lower Z-axis to cutting depth
25
-
26
- G1 X10 Y0 ; Cut to the first corner
27
- G1 X10 Y10 ; Cut to the second corner
28
- G1 X0 Y10 ; Cut to the third corner
29
- G1 X0 Y0 ; Return to the start position
30
-
31
- G0 Z5 ; Raise Z-axis to safe height
32
- M30 ; End program
33
- """
34
-
35
- # Save the G-Code to a file
36
- gcode_file = os.path.join(output_dir, "generated_gcode.nc")
37
- with open(gcode_file, "w") as f:
38
- f.write(gcode_content)
39
-
40
- return gcode_file
41
- except Exception as e:
42
- return f"Error in G-Code generation: {e}"
43
 
44
  def automate_workflow(cad_file):
45
  """
46
  Automates the workflow:
47
- 1. Run Simulation in ANSYS
48
- 2. Generate G-Code for CNC
 
49
  """
50
- # Step 1: Run Simulation in ANSYS
51
- simulation_results = run_simulation(cad_file)
 
 
 
52
 
53
- # Step 2: Generate G-Code
54
- gcode_file = generate_gcode(cad_file)
55
 
56
  return simulation_results, gcode_file
57
 
@@ -59,13 +25,13 @@ def automate_workflow(cad_file):
59
  interface = gr.Interface(
60
  fn=automate_workflow,
61
  inputs=[
62
- gr.File(label="Upload CAD File (.step format)")
63
  ],
64
  outputs=[
65
  gr.Text(label="Simulation Results"),
66
  gr.File(label="Generated G-Code File")
67
  ],
68
- title="ANSYS Simulation and G-Code Generation"
69
  )
70
 
71
  if __name__ == "__main__":
 
 
1
  import gradio as gr
2
+ from utils.cad_utils import convert_cad_to_step
3
  from utils.ansys_utils import run_simulation
4
+ from utils.gcode_utils import generate_gcode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  def automate_workflow(cad_file):
7
  """
8
  Automates the workflow:
9
+ 1. Convert CAD file to STEP format.
10
+ 2. Run simulation in ANSYS.
11
+ 3. Generate G-Code for CNC.
12
  """
13
+ # Step 1: Convert CAD to STEP format
14
+ step_file = convert_cad_to_step(cad_file)
15
+
16
+ # Step 2: Run simulation in ANSYS
17
+ simulation_results = run_simulation(step_file)
18
 
19
+ # Step 3: Generate G-Code
20
+ gcode_file = generate_gcode(step_file)
21
 
22
  return simulation_results, gcode_file
23
 
 
25
  interface = gr.Interface(
26
  fn=automate_workflow,
27
  inputs=[
28
+ gr.File(label="Upload CAD File (SolidWorks/SolidEdge)"),
29
  ],
30
  outputs=[
31
  gr.Text(label="Simulation Results"),
32
  gr.File(label="Generated G-Code File")
33
  ],
34
+ title="CAD to CNC Automation Workflow"
35
  )
36
 
37
  if __name__ == "__main__":