jithenderchoudary commited on
Commit
9ec48a7
·
verified ·
1 Parent(s): e654e71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -5,28 +5,26 @@ import numpy as np
5
  import pyvista as pv
6
  from pyvistaqt import BackgroundPlotter
7
 
8
-
9
  # Function to load a STEP file and display it
10
  def load_and_display_step(file):
11
  try:
12
  # Load STEP file
13
  model = cq.importers.importStep(file.name)
14
-
15
  # Export as STL for visualization
16
  stl_file = "temp_model.stl"
17
  exporters.export(model, stl_file)
18
-
19
  # Render with PyVista
20
  mesh = pv.read(stl_file)
21
  plotter = BackgroundPlotter()
22
  plotter.add_mesh(mesh, color="lightblue")
23
  plotter.show()
24
-
25
  return "File loaded and displayed successfully!"
26
  except Exception as e:
27
  return f"Error: {str(e)}"
28
 
29
-
30
  # Function to run a simple stress analysis (placeholder logic)
31
  def stress_analysis(press_force, area):
32
  try:
@@ -35,29 +33,27 @@ def stress_analysis(press_force, area):
35
  except ZeroDivisionError:
36
  return "Error: Area cannot be zero."
37
 
38
-
39
  # Create Gradio Interface
40
  def main():
41
  with gr.Blocks() as app:
42
  gr.Markdown("# Press Tool Design Simulation")
43
-
44
  with gr.Row():
45
  file_input = gr.File(label="Upload STEP File")
46
  file_output = gr.Textbox(label="File Status")
47
  file_submit = gr.Button("Load and Display STEP File")
48
-
49
  with gr.Row():
50
  force_input = gr.Number(label="Press Force (N)", value=1000)
51
  area_input = gr.Number(label="Contact Area (m²)", value=0.01)
52
  stress_output = gr.Textbox(label="Stress Analysis Result")
53
  stress_submit = gr.Button("Calculate Stress")
54
-
55
  # Events
56
  file_submit.click(fn=load_and_display_step, inputs=file_input, outputs=file_output)
57
  stress_submit.click(fn=stress_analysis, inputs=[force_input, area_input], outputs=stress_output)
58
-
59
- app.launch()
60
 
 
61
 
62
  # Run the app
63
  if __name__ == "__main__":
 
5
  import pyvista as pv
6
  from pyvistaqt import BackgroundPlotter
7
 
 
8
  # Function to load a STEP file and display it
9
  def load_and_display_step(file):
10
  try:
11
  # Load STEP file
12
  model = cq.importers.importStep(file.name)
13
+
14
  # Export as STL for visualization
15
  stl_file = "temp_model.stl"
16
  exporters.export(model, stl_file)
17
+
18
  # Render with PyVista
19
  mesh = pv.read(stl_file)
20
  plotter = BackgroundPlotter()
21
  plotter.add_mesh(mesh, color="lightblue")
22
  plotter.show()
23
+
24
  return "File loaded and displayed successfully!"
25
  except Exception as e:
26
  return f"Error: {str(e)}"
27
 
 
28
  # Function to run a simple stress analysis (placeholder logic)
29
  def stress_analysis(press_force, area):
30
  try:
 
33
  except ZeroDivisionError:
34
  return "Error: Area cannot be zero."
35
 
 
36
  # Create Gradio Interface
37
  def main():
38
  with gr.Blocks() as app:
39
  gr.Markdown("# Press Tool Design Simulation")
40
+
41
  with gr.Row():
42
  file_input = gr.File(label="Upload STEP File")
43
  file_output = gr.Textbox(label="File Status")
44
  file_submit = gr.Button("Load and Display STEP File")
45
+
46
  with gr.Row():
47
  force_input = gr.Number(label="Press Force (N)", value=1000)
48
  area_input = gr.Number(label="Contact Area (m²)", value=0.01)
49
  stress_output = gr.Textbox(label="Stress Analysis Result")
50
  stress_submit = gr.Button("Calculate Stress")
51
+
52
  # Events
53
  file_submit.click(fn=load_and_display_step, inputs=file_input, outputs=file_output)
54
  stress_submit.click(fn=stress_analysis, inputs=[force_input, area_input], outputs=stress_output)
 
 
55
 
56
+ app.launch()
57
 
58
  # Run the app
59
  if __name__ == "__main__":