karthikmn commited on
Commit
73c5836
·
verified ·
1 Parent(s): b625db9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -1,8 +1,52 @@
 
1
  import gradio as gr
2
  from utils.ansys_utils import run_simulation
3
- from utils.cnc_utils import generate_gcode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def automate_workflow(cad_file):
 
 
 
 
 
6
  # Step 1: Run Simulation in ANSYS
7
  simulation_results = run_simulation(cad_file)
8
 
 
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