Spaces:
Build error
Build error
| import gradio as gr | |
| from utils.cad_operations import create_cad_model | |
| from utils.toolpath_generation import generate_toolpath, generate_gcode | |
| # Step 1: Collect user input parameters | |
| def cnc_workflow(length, width, height, material, tool_size, operation_type): | |
| """ | |
| Full CNC workflow from parameter input to G-code generation | |
| """ | |
| # Step 2: Create CAD model | |
| part = create_cad_model(length, width, height, material) | |
| # Step 3: Generate Toolpath | |
| toolpath = generate_toolpath(part, tool_size, operation_type) | |
| # Step 4: Generate G-code | |
| gcode_file = generate_gcode(toolpath) | |
| return f"G-code file generated: {gcode_file}" | |
| # Define the Gradio interface and layout | |
| def build_gui(): | |
| with gr.Blocks() as demo: | |
| # Title and Intro | |
| gr.Markdown("### CNC G-Code Generation Workflow") | |
| # Step 1: Input Parameters | |
| with gr.Row(): | |
| length_input = gr.Number(label="Length (mm)", value=100) | |
| width_input = gr.Number(label="Width (mm)", value=50) | |
| height_input = gr.Number(label="Height (mm)", value=20) | |
| material_input = gr.Dropdown(choices=["Aluminum", "Steel", "Plastic"], label="Material Type", value="Aluminum") | |
| # Step 2: Tool and Operation Input | |
| with gr.Row(): | |
| tool_size_input = gr.Number(label="Tool Size (mm)", value=5) | |
| operation_input = gr.Dropdown(choices=["Milling", "Drilling"], label="Operation Type", value="Milling") | |
| # Step 3: Button to Start G-Code Generation | |
| generate_button = gr.Button("Generate G-Code") | |
| # Step 4: Output section | |
| output_text = gr.Textbox(label="Generated G-code File", interactive=False) | |
| # Bind the button to the function | |
| generate_button.click(cnc_workflow, | |
| inputs=[length_input, width_input, height_input, material_input, tool_size_input, operation_input], | |
| outputs=output_text) | |
| return demo | |
| # Launch the Gradio app | |
| demo = build_gui() | |
| demo.launch() | |