Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# APDL Script for ANSYS
|
| 4 |
apdl_script = """/CLEAR ! Clear any existing database
|
|
@@ -88,5 +115,23 @@ with gr.Blocks() as app:
|
|
| 88 |
modify_button.click(modify_apdl_script, inputs=apdl_view, outputs=step_output)
|
| 89 |
execute_button.click(execute_script, outputs=execution_output)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
# Launch the app
|
| 92 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def execute_script():
|
| 6 |
+
"""Function to execute the APDL script using ANSYS."""
|
| 7 |
+
global apdl_script
|
| 8 |
+
|
| 9 |
+
# Save the APDL script to a file
|
| 10 |
+
script_file = "script.dat"
|
| 11 |
+
with open(script_file, "w") as f:
|
| 12 |
+
f.write(apdl_script)
|
| 13 |
+
|
| 14 |
+
# Define ANSYS execution command
|
| 15 |
+
ansys_command = [
|
| 16 |
+
"ansys", # Replace with the full path to your ANSYS executable, e.g., "C:\\Program Files\\ANSYS Inc\\v211\\ansys.exe"
|
| 17 |
+
"-b", # Batch mode
|
| 18 |
+
"-i", script_file, # Input script
|
| 19 |
+
"-o", "output.log" # Output log
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
# Run the command
|
| 24 |
+
subprocess.run(ansys_command, check=True)
|
| 25 |
+
return "APDL script executed. Check generated views (2D_View.jpg, 3D_View.jpg)."
|
| 26 |
+
except subprocess.CalledProcessError as e:
|
| 27 |
+
return f"Error executing APDL script: {e}"
|
| 28 |
+
|
| 29 |
|
| 30 |
# APDL Script for ANSYS
|
| 31 |
apdl_script = """/CLEAR ! Clear any existing database
|
|
|
|
| 115 |
modify_button.click(modify_apdl_script, inputs=apdl_view, outputs=step_output)
|
| 116 |
execute_button.click(execute_script, outputs=execution_output)
|
| 117 |
|
| 118 |
+
|
| 119 |
+
if os.path.exists("2D_View.jpg") and os.path.exists("3D_View.jpg"):
|
| 120 |
+
print("Images generated successfully.")
|
| 121 |
+
else:
|
| 122 |
+
print("Error: Images not found.")
|
| 123 |
+
def get_generated_images():
|
| 124 |
+
"""Return the generated 2D and 3D view images."""
|
| 125 |
+
return "2D_View.jpg", "3D_View.jpg"
|
| 126 |
+
|
| 127 |
+
# Add this to the Gradio interface
|
| 128 |
+
with gr.Row():
|
| 129 |
+
gr.Markdown("## Generated Images")
|
| 130 |
+
view_2d = gr.Image(label="2D View")
|
| 131 |
+
view_3d = gr.Image(label="3D View")
|
| 132 |
+
refresh_button = gr.Button("Refresh Images")
|
| 133 |
+
|
| 134 |
+
refresh_button.click(get_generated_images, outputs=[view_2d, view_3d])
|
| 135 |
+
|
| 136 |
# Launch the app
|
| 137 |
app.launch()
|