jithenderchoudary commited on
Commit
6d9bd32
·
verified ·
1 Parent(s): 825e55c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py CHANGED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ # Directories
5
+ TEMPLATE_DIR = "simulations/templates"
6
+ OUTPUT_DIR = "simulations/outputs"
7
+ ASSETS_DIR = "assets"
8
+
9
+ # Ensure output directory exists
10
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
11
+
12
+ # Function to generate CAD files
13
+ def generate_cad(length, width, height, material):
14
+ cad_content = f"CAD File: Box with dimensions {length}x{width}x{height} mm using {material}."
15
+ output_path = os.path.join(OUTPUT_DIR, "generated_cad.txt")
16
+
17
+ with open(output_path, "w") as f:
18
+ f.write(cad_content)
19
+
20
+ return f"CAD file saved at: {output_path}"
21
+
22
+ # Function to set up ANSYS simulation
23
+ def setup_simulation(load, temperature, simulation_type):
24
+ template_path = os.path.join(TEMPLATE_DIR, "apdl_template.txt")
25
+
26
+ try:
27
+ with open(template_path, "r") as f:
28
+ apdl_template = f.read()
29
+ except FileNotFoundError:
30
+ return "APDL template not found. Ensure 'apdl_template.txt' exists in the templates folder."
31
+
32
+ apdl_script = apdl_template.format(
33
+ load=load,
34
+ temperature=temperature,
35
+ simulation_type=simulation_type
36
+ )
37
+
38
+ output_path = os.path.join(OUTPUT_DIR, "simulation_script.inp")
39
+ with open(output_path, "w") as f:
40
+ f.write(apdl_script)
41
+
42
+ return f"Simulation script saved at: {output_path}"
43
+
44
+ # Function to optimize G-Code
45
+ def optimize_gcode(toolpath_file, speed):
46
+ if not os.path.exists(toolpath_file):
47
+ return f"Toolpath file '{toolpath_file}' not found."
48
+
49
+ optimized_content = f"Optimized toolpath for speed {speed} mm/s."
50
+ output_path = os.path.join(OUTPUT_DIR, "optimized_gcode.txt")
51
+
52
+ with open(output_path, "w") as f:
53
+ f.write(optimized_content)
54
+
55
+ return f"Optimized G-Code saved at: {output_path}"
56
+
57
+ # Gradio GUI
58
+ with gr.Blocks() as gui:
59
+ gr.Markdown("# CNC and ANSYS Workflow Automation")
60
+
61
+ with gr.Tab("Parameter Input"):
62
+ length = gr.Number(label="Length (mm)")
63
+ width = gr.Number(label="Width (mm)")
64
+ height = gr.Number(label="Height (mm)")
65
+ material = gr.Textbox(label="Material")
66
+ generate_cad_btn = gr.Button("Generate CAD File")
67
+ cad_output = gr.Textbox(label="CAD Output")
68
+ generate_cad_btn.click(generate_cad, [length, width, height, material], cad_output)
69
+
70
+ with gr.Tab("Simulation Setup"):
71
+ load = gr.Number(label="Load (N)")
72
+ temperature = gr.Number(label="Temperature (°C)")
73
+ simulation_type = gr.Radio(["Structural", "Thermal", "Acoustic"], label="Simulation Type")
74
+ setup_sim_btn = gr.Button("Setup Simulation")
75
+ simulation_output = gr.Textbox(label="Simulation Script Output")
76
+ setup_sim_btn.click(setup_simulation, [load, temperature, simulation_type], simulation_output)
77
+
78
+ with gr.Tab("G-Code Optimization"):
79
+ toolpath_file = gr.Textbox(label="Toolpath File (e.g., toolpath.nc)")
80
+ speed = gr.Number(label="Cutting Speed (mm/s)")
81
+ optimize_btn = gr.Button("Optimize G-Code")
82
+ gcode_output = gr.Textbox(label="Optimized G-Code Output")
83
+ optimize_btn.click(optimize_gcode, [toolpath_file, speed], gcode_output)
84
+
85
+ gui.launch()