Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|