jithenderchoudary commited on
Commit
ab9eaf0
·
verified ·
1 Parent(s): 68c37b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -37
app.py CHANGED
@@ -52,15 +52,6 @@ def execute_script():
52
  """Function to execute the APDL script using ANSYS."""
53
  global apdl_script
54
 
55
- # Save the APDL script to a file
56
- script_file = "script.dat"
57
- with open(script_file, "w") as f:
58
- f.write(apdl_script)
59
-
60
- def execute_script():
61
- """Function to execute the APDL script using ANSYS."""
62
- global apdl_script
63
-
64
  # Save the APDL script to a file
65
  script_file = "script.dat"
66
  with open(script_file, "w") as f:
@@ -85,23 +76,10 @@ def execute_script():
85
  return "APDL script executed, but 2D/3D images are missing. Check output.log for details."
86
 
87
  except subprocess.CalledProcessError as e:
88
- # Return detailed error message
89
  return f"Error executing APDL script: {str(e)}. Check output.log for details."
90
  except FileNotFoundError:
91
  return "ANSYS executable not found. Verify the path in ansys_command."
92
 
93
-
94
- ]
95
-
96
- ]
97
-
98
- try:
99
- # Run the command
100
- subprocess.run(ansys_command, check=True)
101
- return "APDL script executed. Check generated views (2D_View.jpg, 3D_View.jpg)."
102
- except subprocess.CalledProcessError as e:
103
- return f"Error executing APDL script: {e}"
104
-
105
  def get_generated_images():
106
  """Return the generated 2D and 3D view images if they exist."""
107
  if os.path.exists("2D_View.jpg") and os.path.exists("3D_View.jpg"):
@@ -109,6 +87,14 @@ def get_generated_images():
109
  else:
110
  return None, None
111
 
 
 
 
 
 
 
 
 
112
  # Gradio interface
113
  with gr.Blocks() as app:
114
  gr.Markdown("# ANSYS APDL Script for 2D and 3D Views")
@@ -126,7 +112,9 @@ with gr.Blocks() as app:
126
  with gr.Row():
127
  execute_button = gr.Button("Run Script")
128
  execution_output = gr.Text(label="Execution Status")
129
- execute_button.click(execute_script, outputs=execution_output)
 
 
130
 
131
  with gr.Row():
132
  gr.Markdown("## Generated Images")
@@ -135,18 +123,4 @@ with gr.Blocks() as app:
135
  refresh_button = gr.Button("Refresh Images")
136
  refresh_button.click(get_generated_images, outputs=[view_2d, view_3d])
137
 
138
- def read_output_log():
139
- """Read and return the contents of output.log."""
140
- if os.path.exists("output.log"):
141
- with open("output.log", "r") as f:
142
- return f.read()
143
- else:
144
- return "No output log found."
145
-
146
- # Add this to the Gradio interface
147
- log_output = gr.Textbox(label="Output Log", lines=10, interactive=False)
148
- execute_button.click(execute_script, outputs=[execution_output, log_output])
149
-
150
-
151
  app.launch()
152
-
 
52
  """Function to execute the APDL script using ANSYS."""
53
  global apdl_script
54
 
 
 
 
 
 
 
 
 
 
55
  # Save the APDL script to a file
56
  script_file = "script.dat"
57
  with open(script_file, "w") as f:
 
76
  return "APDL script executed, but 2D/3D images are missing. Check output.log for details."
77
 
78
  except subprocess.CalledProcessError as e:
 
79
  return f"Error executing APDL script: {str(e)}. Check output.log for details."
80
  except FileNotFoundError:
81
  return "ANSYS executable not found. Verify the path in ansys_command."
82
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def get_generated_images():
84
  """Return the generated 2D and 3D view images if they exist."""
85
  if os.path.exists("2D_View.jpg") and os.path.exists("3D_View.jpg"):
 
87
  else:
88
  return None, None
89
 
90
+ def read_output_log():
91
+ """Read and return the contents of output.log."""
92
+ if os.path.exists("output.log"):
93
+ with open("output.log", "r") as f:
94
+ return f.read()
95
+ else:
96
+ return "No output log found."
97
+
98
  # Gradio interface
99
  with gr.Blocks() as app:
100
  gr.Markdown("# ANSYS APDL Script for 2D and 3D Views")
 
112
  with gr.Row():
113
  execute_button = gr.Button("Run Script")
114
  execution_output = gr.Text(label="Execution Status")
115
+ log_output = gr.Textbox(label="Output Log", lines=10, interactive=False)
116
+ execute_button.click(execute_script, outputs=[execution_output])
117
+ execute_button.click(read_output_log, outputs=log_output)
118
 
119
  with gr.Row():
120
  gr.Markdown("## Generated Images")
 
123
  refresh_button = gr.Button("Refresh Images")
124
  refresh_button.click(get_generated_images, outputs=[view_2d, view_3d])
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  app.launch()