Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import subprocess
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Function to
|
| 6 |
-
def
|
| 7 |
"""
|
| 8 |
-
|
| 9 |
-
|
| 10 |
"""
|
| 11 |
-
ansys_executable = "path/to/ansys/executable" # Replace with the actual path to ANSYS executable
|
| 12 |
-
script_path = apdl_script.name
|
| 13 |
-
output_log = "simulation_output.log"
|
| 14 |
-
|
| 15 |
try:
|
| 16 |
-
|
| 17 |
-
result = subprocess.run(
|
| 18 |
-
[ansys_executable, "-b", "-i", script_path, "-o", output_log],
|
| 19 |
-
stdout=subprocess.PIPE,
|
| 20 |
-
stderr=subprocess.PIPE,
|
| 21 |
-
text=True
|
| 22 |
-
)
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
-
return f"An error occurred
|
| 37 |
|
| 38 |
# Gradio Interface
|
| 39 |
iface = gr.Interface(
|
| 40 |
-
fn=
|
| 41 |
inputs=gr.File(label="Upload APDL Script"),
|
| 42 |
outputs=gr.Textbox(label="Simulation Log Output"),
|
| 43 |
-
title="APDL Simulation Runner",
|
| 44 |
description=(
|
| 45 |
-
"Upload an APDL script to
|
| 46 |
-
"
|
| 47 |
),
|
| 48 |
)
|
| 49 |
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Function to simulate APDL script execution
|
| 5 |
+
def simulate_apdl_execution(apdl_script):
|
| 6 |
"""
|
| 7 |
+
Simulate the execution of an APDL script.
|
| 8 |
+
This mock function reads the script and returns a simulated output.
|
| 9 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
+
script_path = apdl_script.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Read the uploaded APDL script
|
| 14 |
+
with open(script_path, "r") as file:
|
| 15 |
+
apdl_content = file.read()
|
| 16 |
+
|
| 17 |
+
# Simulate execution (Replace this block with actual execution logic)
|
| 18 |
+
simulation_log = "Simulation Started...\n"
|
| 19 |
+
simulation_log += "========================\n"
|
| 20 |
+
simulation_log += f"Processing Script: {os.path.basename(script_path)}\n"
|
| 21 |
+
simulation_log += f"Script Content:\n{apdl_content}\n"
|
| 22 |
+
simulation_log += "========================\n"
|
| 23 |
+
simulation_log += "Simulation Completed Successfully.\n"
|
| 24 |
+
simulation_log += "Results: Maximum displacement = 0.00123 mm, Stress = 123 MPa\n"
|
| 25 |
+
|
| 26 |
+
return simulation_log
|
| 27 |
except Exception as e:
|
| 28 |
+
return f"An error occurred during simulation: {str(e)}"
|
| 29 |
|
| 30 |
# Gradio Interface
|
| 31 |
iface = gr.Interface(
|
| 32 |
+
fn=simulate_apdl_execution,
|
| 33 |
inputs=gr.File(label="Upload APDL Script"),
|
| 34 |
outputs=gr.Textbox(label="Simulation Log Output"),
|
| 35 |
+
title="APDL Simulation Runner (Mock Version)",
|
| 36 |
description=(
|
| 37 |
+
"Upload an APDL script to simulate running a simulation. "
|
| 38 |
+
"This is a mock version. Replace the logic with real simulation execution as needed."
|
| 39 |
),
|
| 40 |
)
|
| 41 |
|