File size: 2,083 Bytes
0664784
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf12252
0664784
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# gcode_analyzer_ui.py

import gradio as gr
from python_gcode_checker import run_checks
from settings_report_details import generate_detailed_report

def analyze_gcode(gcode, depth_max=0.1):
    errors, warnings = run_checks(gcode, depth_max)
    error_count = len(errors)
    warning_count = len(warnings)
    config_report = generate_detailed_report(gcode)
    return f"Errors: {error_count}\n\n{format_issues(errors)}", f"Warnings: {warning_count}\n\n{format_issues(warnings)}", config_report

def format_issues(issues):
    formatted = []
    for line_num, message in issues:
        if line_num > 0:
            formatted.append(f"Line {line_num}: {message}")
        else:
            formatted.append(message)
    return "\n".join(formatted)

with gr.Blocks() as app:
    gr.Markdown("""
    ### G-code Programming Assistant (v0.1)
    
    Welcome to the G-code Assistant! This tool is solely for educational purposes, helping you verify and analyze your G-code for potential errors and warnings before actually running it on your machine.
    
    **Note:** This tool is limited to simple carving operations on a CNC milling machine.
    
    This is a beta version, and you're free to use it for checking your G-codes. If you encounter any issues or unexpected behavior, please contact the developer at **nico.aspra@bicol-u.edu.ph**.
    """)

    depth_input = gr.Number(value=0.1, label="Maximum Depth of Cut", precision=1)
    
    gcode_input = gr.Textbox(lines=20, label="Input G-code", placeholder="Enter G-code here...")

    analyze_button = gr.Button("Analyze G-code")

    with gr.Row():
        output_errors = gr.Textbox(label="Errors", interactive=False)
        output_warnings = gr.Textbox(label="Warnings", interactive=False)
    output_config = gr.Textbox(label="Configuration Settings", interactive=False)

    analyze_button.click(
        fn=analyze_gcode,
        inputs=[gcode_input, depth_input],
        outputs=[output_errors, output_warnings, output_config]
    )

    gr.Markdown("---")
    gr.Markdown("Developed by **Aspra, N.**")

app.launch()