jithenderchoudary commited on
Commit
6126a18
·
verified ·
1 Parent(s): f3e2407

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -25
app.py CHANGED
@@ -6,31 +6,42 @@ import os
6
 
7
  # Sample simulation function for illustration purposes
8
  def run_simulation(material_yield, part_thickness, press_force, punch_speed, safety_factor):
9
- # Generate dummy data for simulation results
10
- x = np.linspace(0, 10, 100)
11
- y = np.sin(x) * material_yield * part_thickness / safety_factor # Simulated stress distribution
12
-
13
- # Plotting the stress analysis graph
14
- plt.figure(figsize=(6, 4))
15
- plt.plot(x, y, label="Stress Distribution")
16
- plt.title(f"Stress Analysis: Yield={material_yield}, Thickness={part_thickness}, Force={press_force}, Speed={punch_speed}")
17
- plt.xlabel("X-axis (Position)")
18
- plt.ylabel("Stress (MPa)")
19
- plt.legend()
20
- plt.grid(True)
21
- graph_output_path = "/tmp/simulation_output.png"
22
- plt.savefig(graph_output_path)
23
- plt.close()
24
-
25
- # 3D Model Visualization using PyVista
26
- mesh = pv.Sphere(radius=part_thickness) # Dummy sphere, replace with actual part geometry
27
- plotter = pv.Plotter()
28
- plotter.add_mesh(mesh)
29
- plotter.view_xy()
30
- plotter_output_path = "/tmp/3d_model_output.png"
31
- plotter.screenshot(plotter_output_path)
32
-
33
- return graph_output_path, plotter_output_path
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # Gradio interface for input parameters and output visualization
36
  iface = gr.Interface(
 
6
 
7
  # Sample simulation function for illustration purposes
8
  def run_simulation(material_yield, part_thickness, press_force, punch_speed, safety_factor):
9
+ try:
10
+ # Generate dummy data for simulation results
11
+ x = np.linspace(0, 10, 100)
12
+ y = np.sin(x) * material_yield * part_thickness / safety_factor # Simulated stress distribution
13
+
14
+ # Plotting the stress analysis graph
15
+ plt.figure(figsize=(6, 4))
16
+ plt.plot(x, y, label="Stress Distribution")
17
+ plt.title(f"Stress Analysis: Yield={material_yield}, Thickness={part_thickness}, Force={press_force}, Speed={punch_speed}")
18
+ plt.xlabel("X-axis (Position)")
19
+ plt.ylabel("Stress (MPa)")
20
+ plt.legend()
21
+ plt.grid(True)
22
+ graph_output_path = "/tmp/simulation_output.png"
23
+ plt.savefig(graph_output_path)
24
+ plt.close()
25
+
26
+ print(f"Graph saved at {graph_output_path}") # Debug message
27
+
28
+ # 3D Model Visualization using PyVista
29
+ mesh = pv.Sphere(radius=part_thickness) # Dummy sphere, replace with actual part geometry
30
+ plotter = pv.Plotter()
31
+ plotter.add_mesh(mesh)
32
+ plotter.view_xy()
33
+
34
+ # Save the screenshot of the 3D model
35
+ plotter_output_path = "/tmp/3d_model_output.png"
36
+ plotter.screenshot(plotter_output_path)
37
+
38
+ print(f"3D Model screenshot saved at {plotter_output_path}") # Debug message
39
+
40
+ return graph_output_path, plotter_output_path
41
+
42
+ except Exception as e:
43
+ print(f"Error during simulation: {e}")
44
+ return None, None
45
 
46
  # Gradio interface for input parameters and output visualization
47
  iface = gr.Interface(