Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def generate_gcode(diameter, length, radius1, radius2):
|
| 4 |
+
"""
|
| 5 |
+
Generates CNC G-code based on input parameters.
|
| 6 |
+
"""
|
| 7 |
+
gcode = f"""%
|
| 8 |
+
O1000 (CNC PROGRAM FOR TURNED PART)
|
| 9 |
+
G21 (Units in mm)
|
| 10 |
+
G28 U0 W0 (Home Position)
|
| 11 |
+
G50 S1500 (Max RPM)
|
| 12 |
+
G96 S200 M03 (Spindle ON with Constant Surface Speed)
|
| 13 |
+
|
| 14 |
+
(START TURNING PROFILE)
|
| 15 |
+
G00 X{diameter + 5.0} Z5.0
|
| 16 |
+
G01 Z0.0 F0.25
|
| 17 |
+
G01 X0.0 F0.25
|
| 18 |
+
|
| 19 |
+
(ROUGH TURNING OPERATION)
|
| 20 |
+
G00 X{diameter + 5.0} Z2.0
|
| 21 |
+
G01 Z0.0 F0.25
|
| 22 |
+
G01 X{diameter} Z-2.0
|
| 23 |
+
G02 X{diameter - 2.5} Z-2.75 R{radius1}
|
| 24 |
+
G01 X{diameter - 2.5} Z-4.125
|
| 25 |
+
G02 X{diameter - 5.0} Z-5.0 R{radius2}
|
| 26 |
+
G01 X{diameter - 5.0} Z-{length}
|
| 27 |
+
|
| 28 |
+
(END OF OPERATION)
|
| 29 |
+
G00 X{diameter + 5.0} Z5.0
|
| 30 |
+
G28 U0 W0
|
| 31 |
+
M30
|
| 32 |
+
%
|
| 33 |
+
"""
|
| 34 |
+
return gcode
|
| 35 |
+
|
| 36 |
+
# Gradio interface
|
| 37 |
+
with gr.Blocks() as app:
|
| 38 |
+
gr.Markdown("# CNC G-Code Generator for Turned Parts")
|
| 39 |
+
gr.Markdown("Input your dimensions to generate G-Code:")
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
diameter_input = gr.Number(label="Diameter (mm)", value=50)
|
| 43 |
+
length_input = gr.Number(label="Length (mm)", value=30)
|
| 44 |
+
radius1_input = gr.Number(label="Radius R1 (mm)", value=2.5)
|
| 45 |
+
radius2_input = gr.Number(label="Radius R2 (mm)", value=1.25)
|
| 46 |
+
|
| 47 |
+
generate_button = gr.Button("Generate G-Code")
|
| 48 |
+
gcode_output = gr.Textbox(label="Generated G-Code", lines=20)
|
| 49 |
+
|
| 50 |
+
generate_button.click(
|
| 51 |
+
generate_gcode,
|
| 52 |
+
inputs=[diameter_input, length_input, radius1_input, radius2_input],
|
| 53 |
+
outputs=gcode_output
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
app.launch()
|