import gradio as gr import subprocess import os def process_step_file(file): """Process the uploaded STEP file and run the APDL script.""" step_file_path = file.name apdl_script = f""" /CLEAR /CWD, '{os.getcwd()}' /PREP7 /IMPORT, STEP, '{step_file_path}' NUMMRG, ALL ET, 1, SOLID186 ESIZE, 10 AMESH, ALL MP, EX, 1, 200E9 MP, PRXY, 1, 0.3 D, ALL, UX, 0 D, ALL, UY, 0 F, NODE(0, 0, 0), FX, 1000 FINISH /SOLU ANTYPE, 0 SOLVE FINISH /POST1 /SHOW, JPEG PLNSOL, U, SUM FILE, '2D_View', 'JPEG' /SHOW, CLOSE /VIEW, 1, 1, 1, 1 PLNSOL, S, EQV FILE, '3D_View', 'JPEG' /SHOW, CLOSE FINISH """ script_file = "script.dat" with open(script_file, "w") as f: f.write(apdl_script) ansys_command = [ "C:\\Program Files\\ANSYS Inc\\v211\\ansys\\bin\\winx64\\ansys211.exe", "-b", "-i", script_file, "-o", "output.log" ] try: subprocess.run(ansys_command, check=True) if os.path.exists("2D_View.jpg") and os.path.exists("3D_View.jpg"): return "Script executed successfully. Results generated." else: return "Execution completed, but results not found." except Exception as e: return f"Error executing script: {str(e)}" with gr.Blocks() as app: gr.Markdown("# ANSYS STEP File Processing") with gr.Row(): step_file = gr.File(label="Upload STEP File") process_button = gr.Button("Process File") output = gr.Text(label="Output Log") process_button.click(process_step_file, inputs=step_file, outputs=output) with gr.Row(): gr.Markdown("## Generated Views") view_2d = gr.Image(label="2D View") view_3d = gr.Image(label="3D View") refresh_button = gr.Button("Refresh Results") refresh_button.click(lambda: ("2D_View.jpg", "3D_View.jpg"), outputs=[view_2d, view_3d]) app.launch()