Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -444,4 +444,72 @@ with gr.Blocks(theme=gr.themes.Soft(), title="CAD-Wizard") as demo:
|
|
| 444 |
gr.Markdown("### Obstacle (set all to 0 for none)")
|
| 445 |
cfd_ox1 = gr.Slider(0.0, 5.0, value=0.5, label="Obstacle X1")
|
| 446 |
cfd_oy1 = gr.Slider(0.0, 2.0, value=0.4, label="Obstacle Y1")
|
| 447 |
-
cfd_ox2 = gr.Slider(0.0, 5.0, value=0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
gr.Markdown("### Obstacle (set all to 0 for none)")
|
| 445 |
cfd_ox1 = gr.Slider(0.0, 5.0, value=0.5, label="Obstacle X1")
|
| 446 |
cfd_oy1 = gr.Slider(0.0, 2.0, value=0.4, label="Obstacle Y1")
|
| 447 |
+
cfd_ox2 = gr.Slider(0.0, 5.0, value=0.7, label="Obstacle X2")
|
| 448 |
+
cfd_oy2 = gr.Slider(0.0, 2.0, value=0.6, label="Obstacle Y2")
|
| 449 |
+
|
| 450 |
+
gr.Markdown("### Solver Settings")
|
| 451 |
+
cfd_Nx = gr.Slider(31, 101, value=61, step=10, label="Grid Points (X)")
|
| 452 |
+
cfd_Ny = gr.Slider(21, 81, value=41, step=10, label="Grid Points (Y)")
|
| 453 |
+
|
| 454 |
+
cfd_button = gr.Button("Run Simulation", variant="primary")
|
| 455 |
+
|
| 456 |
+
with gr.Column(scale=2):
|
| 457 |
+
cfd_plot_output = gr.Plot(label="CFD Results")
|
| 458 |
+
cfd_summary_output = gr.Markdown(label="Simulation Summary")
|
| 459 |
+
|
| 460 |
+
# --- TAB 3: Text to CAD Model ---
|
| 461 |
+
with gr.TabItem("Text to CAD Model", id=2):
|
| 462 |
+
with gr.Row():
|
| 463 |
+
with gr.Column(scale=1):
|
| 464 |
+
text_cad_input = gr.Textbox(lines=5, label="Describe the part you want to create", placeholder="e.g., A gear with radius 20 and thickness 5")
|
| 465 |
+
text_cad_button = gr.Button("Generate CAD Model", variant="primary")
|
| 466 |
+
with gr.Column(scale=2):
|
| 467 |
+
text_cad_drawing = gr.Plot(label="2D Technical Drawing")
|
| 468 |
+
text_cad_3d_plot = gr.Plot(label="Interactive 3D Model")
|
| 469 |
+
text_cad_file = gr.File(label="Download 3D Model (.stl)")
|
| 470 |
+
gr.Examples(
|
| 471 |
+
[["A plate with length 100, width 50, and thickness 10"],
|
| 472 |
+
["A pipe with radius 15, thickness 3 and length 120"]],
|
| 473 |
+
inputs=text_cad_input
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
# --- TAB 4: Text to G-Code ---
|
| 477 |
+
with gr.TabItem("Text to G-Code", id=3):
|
| 478 |
+
with gr.Row():
|
| 479 |
+
with gr.Column(scale=1):
|
| 480 |
+
text_gcode_input = gr.Textbox(lines=5, label="Describe the 2D part to be cut", placeholder="A 150x75 plate with a 10mm hole at (30, 40)")
|
| 481 |
+
text_gcode_button = gr.Button("Generate G-Code", variant="primary")
|
| 482 |
+
with gr.Column(scale=2):
|
| 483 |
+
text_gcode_drawing = gr.Image(label="2D Part Drawing")
|
| 484 |
+
text_gcode_output = gr.Code(label="Generated G-Code", language="gcode")
|
| 485 |
+
text_gcode_file = gr.File(label="Download Drawing (.svg)")
|
| 486 |
+
gr.Examples(
|
| 487 |
+
[["A 100x50 plate with a 20mm hole at (50, 25) and a 10mm hole at (80, 25)"]],
|
| 488 |
+
inputs=text_gcode_input
|
| 489 |
+
)
|
| 490 |
+
|
| 491 |
+
# --- Button Click Handlers ---
|
| 492 |
+
cad_2d_button.click(generate_ortho_views, inputs=[cad_file_input], outputs=[cad_2d_output])
|
| 493 |
+
|
| 494 |
+
cfd_button.click(run_cfd_simulation,
|
| 495 |
+
inputs=[cfd_Lx, cfd_Ly, cfd_Nx, cfd_Ny, cfd_u_in, cfd_rho, cfd_mu, cfd_ox1, cfd_oy1, cfd_ox2, cfd_oy2,
|
| 496 |
+
gr.State(2000), gr.State(50), gr.State(1e-4)],
|
| 497 |
+
outputs=[cfd_plot_output, cfd_summary_output])
|
| 498 |
+
|
| 499 |
+
text_cad_button.click(text_to_cad_generator.run,
|
| 500 |
+
inputs=[text_cad_input],
|
| 501 |
+
outputs=[text_cad_drawing, text_cad_3d_plot, text_cad_file])
|
| 502 |
+
|
| 503 |
+
text_gcode_button.click(generate_text_to_gcode,
|
| 504 |
+
inputs=[text_gcode_input],
|
| 505 |
+
outputs=[text_gcode_drawing, text_gcode_output, text_gcode_file])
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
if __name__ == "__main__":
|
| 509 |
+
# Create some example files for the first tab
|
| 510 |
+
if not os.path.exists("examples"):
|
| 511 |
+
os.makedirs("examples")
|
| 512 |
+
trimesh.creation.box(extents=[50,30,40]).export("examples/bracket.stl")
|
| 513 |
+
trimesh.creation.gear(tooth_number=12, radial_pitch=20).export("examples/gear.stl")
|
| 514 |
+
|
| 515 |
+
demo.launch()
|