jithenderchoudary commited on
Commit
a77fc10
·
verified ·
1 Parent(s): 4ce5147

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -1,22 +1,17 @@
1
  import gradio as gr
2
- import cadquery as cq
3
- from cadquery import exporters
4
- import matplotlib.pyplot as plt
5
  import numpy as np
6
- import os
 
 
7
 
 
8
  def process_step_file(step_file):
9
- # Save the uploaded file temporarily
10
- step_path = step_file.name
11
-
12
- # Load STEP file using CadQuery
13
  try:
14
- model = cq.importers.importStep(step_path)
15
- # Export 2D projection to SVG for visualization
16
- svg_path = "projection.svg"
17
- exporters.export(model, svg_path)
18
 
19
- # Generate G-code (dummy example for simplicity)
20
  gcode = "G21 ; Set units to millimeters\n"
21
  gcode += "G17 ; Select XY plane\n"
22
  gcode += "G90 ; Absolute positioning\n"
@@ -29,18 +24,18 @@ def process_step_file(step_file):
29
  gcode += "G1 X0 Y0 ; Return to origin\n"
30
  gcode += "G0 Z5 ; Move Z axis up\n"
31
  gcode += "M30 ; End of program"
32
-
33
- # 2D Visualization
34
  fig, ax = plt.subplots()
35
- ax.plot([0, 10, 10, 0, 0], [0, 0, 10, 10, 0], marker="o") # Simple 2D Graph example
36
  ax.set_title("2D Visualization (Placeholder)")
37
  ax.set_xlabel("X Axis")
38
  ax.set_ylabel("Y Axis")
39
  plt_path = "2d_visualization.png"
40
  plt.savefig(plt_path)
41
 
42
- # Return results
43
- return plt_path, svg_path, gcode
44
  except Exception as e:
45
  return f"Error: {str(e)}", None, None
46
 
 
1
  import gradio as gr
 
 
 
2
  import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ from OCC.Extend.DataExchange import read_step_file
5
+ from OCC.Extend.ShapeFactory import make_box
6
 
7
+ # Function to process the STEP file
8
  def process_step_file(step_file):
 
 
 
 
9
  try:
10
+ # Load STEP file using pythonOCC
11
+ step_path = step_file.name
12
+ shape = read_step_file(step_path)
 
13
 
14
+ # Generate G-code (simple mock-up)
15
  gcode = "G21 ; Set units to millimeters\n"
16
  gcode += "G17 ; Select XY plane\n"
17
  gcode += "G90 ; Absolute positioning\n"
 
24
  gcode += "G1 X0 Y0 ; Return to origin\n"
25
  gcode += "G0 Z5 ; Move Z axis up\n"
26
  gcode += "M30 ; End of program"
27
+
28
+ # 2D Visualization (simple projection using matplotlib)
29
  fig, ax = plt.subplots()
30
+ ax.plot([0, 10, 10, 0, 0], [0, 0, 10, 10, 0], marker="o") # Basic square for placeholder
31
  ax.set_title("2D Visualization (Placeholder)")
32
  ax.set_xlabel("X Axis")
33
  ax.set_ylabel("Y Axis")
34
  plt_path = "2d_visualization.png"
35
  plt.savefig(plt_path)
36
 
37
+ # Return 2D Visualization image, G-code, and a simple 3D SVG (for demonstration)
38
+ return plt_path, "Projection.svg", gcode
39
  except Exception as e:
40
  return f"Error: {str(e)}", None, None
41