Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,20 @@ import matplotlib.pyplot as plt
|
|
| 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
|
|
@@ -15,51 +29,6 @@ def generate_views(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:
|
|
@@ -123,7 +92,7 @@ def main():
|
|
| 123 |
|
| 124 |
# Events for Visualization
|
| 125 |
generate_views_btn.click(
|
| 126 |
-
fn=
|
| 127 |
inputs=step_input,
|
| 128 |
outputs=[two_d_output, three_d_output]
|
| 129 |
)
|
|
|
|
| 8 |
import json
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
# Define missing generate_2d_view and generate_3d_view functions
|
| 12 |
+
def generate_2d_view(step_file):
|
| 13 |
+
# Example logic for 2D view generation
|
| 14 |
+
model = cq.importers.importStep(step_file.name)
|
| 15 |
+
two_d_image = model.toSvg()
|
| 16 |
+
return two_d_image
|
| 17 |
+
|
| 18 |
+
def generate_3d_view(step_file):
|
| 19 |
+
# Example logic for 3D view generation
|
| 20 |
+
model = cq.importers.importStep(step_file.name)
|
| 21 |
+
mesh = trimesh.Trimesh(vertices=model.val().vertices, faces=model.val().faces)
|
| 22 |
+
three_d_image = mesh.show()
|
| 23 |
+
return three_d_image
|
| 24 |
+
|
| 25 |
# Wrapper function to generate both 2D and 3D views
|
| 26 |
def generate_views(step_file):
|
| 27 |
# Call the individual functions and collect their outputs
|
|
|
|
| 29 |
three_d_view = generate_3d_view(step_file)
|
| 30 |
return two_d_view, three_d_view
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# APDL Script Generation
|
| 33 |
def generate_apdl_script(file, press_force, material_json):
|
| 34 |
try:
|
|
|
|
| 92 |
|
| 93 |
# Events for Visualization
|
| 94 |
generate_views_btn.click(
|
| 95 |
+
fn=generate_views, # Use the wrapper function
|
| 96 |
inputs=step_input,
|
| 97 |
outputs=[two_d_output, three_d_output]
|
| 98 |
)
|