jithenderchoudary commited on
Commit
8cf1897
·
verified ·
1 Parent(s): 71472a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cadquery as cq
3
+ from cadquery import exporters
4
+ 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:
33
+ stress = press_force / area # Stress = Force / Area
34
+ return f"Calculated Stress: {stress} N/m²"
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__":
64
+ main()