karthikmn commited on
Commit
48f3f0b
·
verified ·
1 Parent(s): d597f80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
app.py CHANGED
@@ -1,49 +1,41 @@
1
  import gradio as gr
2
- import subprocess
3
  import os
4
 
5
- # Function to execute the APDL script using ANSYS
6
- def run_apdl_simulation(apdl_script):
7
  """
8
- Execute the given APDL script using ANSYS.
9
- Returns the log output or error messages.
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
- # Run the ANSYS simulation
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
- # Check for errors
25
- if result.returncode != 0:
26
- return f"Simulation failed with error:\n{result.stderr}"
27
-
28
- # Return simulation log output
29
- if os.path.exists(output_log):
30
- with open(output_log, "r") as log_file:
31
- log_content = log_file.read()
32
- return log_content
33
- else:
34
- return "Simulation completed, but the output log was not generated."
 
 
 
35
  except Exception as e:
36
- return f"An error occurred while running the simulation: {str(e)}"
37
 
38
  # Gradio Interface
39
  iface = gr.Interface(
40
- fn=run_apdl_simulation,
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 run a simulation using ANSYS. "
46
- "The script will be executed, and the output log will be displayed."
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