Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,45 +8,58 @@ import matplotlib.pyplot as plt
|
|
| 8 |
import json
|
| 9 |
import os
|
| 10 |
|
| 11 |
-
# 2D
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
buffer = BytesIO()
|
| 23 |
-
plt.savefig(buffer, format="png")
|
| 24 |
-
buffer.seek(0)
|
| 25 |
-
return buffer
|
| 26 |
-
except Exception as e:
|
| 27 |
-
return f"Error in generating 2D view: {e}"
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
try:
|
| 32 |
-
model = cq.importers.importStep(step_file.name)
|
| 33 |
-
stl_file = "temp_model.stl"
|
| 34 |
-
exporters.export(model, stl_file)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
|
|
|
| 50 |
# APDL Script Generation
|
| 51 |
def generate_apdl_script(file, press_force, material_json):
|
| 52 |
try:
|
|
|
|
| 8 |
import json
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
# Wrapper function to generate both 2D and 3D views
|
| 12 |
+
def generate_views(step_file):
|
| 13 |
+
# Call the individual functions and collect their outputs
|
| 14 |
+
two_d_view = generate_2d_view(step_file)
|
| 15 |
+
three_d_view = generate_3d_view(step_file)
|
| 16 |
+
return two_d_view, three_d_view
|
| 17 |
+
|
| 18 |
+
# Updated Gradio Interface
|
| 19 |
+
def main():
|
| 20 |
+
with gr.Blocks() as app:
|
| 21 |
+
gr.Markdown("# Press Tool Design and APDL Script Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
with gr.Row():
|
| 24 |
+
step_input = gr.File(label="Upload STEP File")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
with gr.Row():
|
| 27 |
+
two_d_output = gr.Image(label="2D View")
|
| 28 |
+
three_d_output = gr.Image(label="3D View")
|
| 29 |
+
generate_views_btn = gr.Button("Generate 2D & 3D Views")
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
force_input = gr.Number(label="Press Force (N)", value=1000)
|
| 33 |
+
material_input = gr.Textbox(
|
| 34 |
+
label="Material Properties (JSON)",
|
| 35 |
+
value='{"elastic_modulus": 2e11, "poisson": 0.3}'
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
script_output = gr.Textbox(label="Generated APDL Script", interactive=False)
|
| 40 |
+
download_button = gr.File(label="Download Script")
|
| 41 |
+
generate_apdl_btn = gr.Button("Generate APDL Script")
|
| 42 |
+
|
| 43 |
+
# Events for Visualization
|
| 44 |
+
generate_views_btn.click(
|
| 45 |
+
fn=generate_views, # Use the wrapper function
|
| 46 |
+
inputs=step_input,
|
| 47 |
+
outputs=[two_d_output, three_d_output]
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Events for APDL Script
|
| 51 |
+
def handle_download(apdl_script, apdl_file_path):
|
| 52 |
+
if apdl_file_path and os.path.exists(apdl_file_path):
|
| 53 |
+
return apdl_file_path
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
generate_apdl_btn.click(
|
| 57 |
+
fn=generate_apdl_script,
|
| 58 |
+
inputs=[step_input, force_input, material_input],
|
| 59 |
+
outputs=[script_output, download_button]
|
| 60 |
+
)
|
| 61 |
|
| 62 |
+
|
| 63 |
# APDL Script Generation
|
| 64 |
def generate_apdl_script(file, press_force, material_json):
|
| 65 |
try:
|