Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,37 +5,46 @@ import gradio as gr
|
|
| 5 |
|
| 6 |
# Function for Progressive Die Design
|
| 7 |
def generate_die(length, width, thickness):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Function for Stress Analysis
|
| 16 |
def stress_analysis(force, die_width, die_height, material_strength):
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Function for Tool Optimization
|
| 29 |
def optimize_tool(speed, feed_rate, depth_of_cut, material):
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Gradio interface functions
|
| 41 |
def progressive_die_interface(length, width, thickness):
|
|
|
|
| 5 |
|
| 6 |
# Function for Progressive Die Design
|
| 7 |
def generate_die(length, width, thickness):
|
| 8 |
+
try:
|
| 9 |
+
plate = cq.Workplane("XY").box(length, width, thickness)
|
| 10 |
+
punch = cq.Workplane("XY").rect(10, 10).extrude(5).translate((length/4, width/4, thickness/2))
|
| 11 |
+
die = plate.cut(punch)
|
| 12 |
+
filename = "progressive_die.step"
|
| 13 |
+
cq.exporters.export(die, filename)
|
| 14 |
+
return f"Progressive die design saved as {filename}"
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error generating die: {str(e)}"
|
| 17 |
|
| 18 |
# Function for Stress Analysis
|
| 19 |
def stress_analysis(force, die_width, die_height, material_strength):
|
| 20 |
+
try:
|
| 21 |
+
stress = force / (die_width * die_height)
|
| 22 |
+
safety_factor = material_strength / stress
|
| 23 |
+
|
| 24 |
+
fig, ax = plt.subplots()
|
| 25 |
+
ax.bar(["Stress", "Material Strength"], [stress, material_strength])
|
| 26 |
+
ax.set_ylabel("Stress (MPa)")
|
| 27 |
+
ax.set_title("Stress Analysis")
|
| 28 |
+
plt.close(fig)
|
| 29 |
+
|
| 30 |
+
return f"Safety Factor: {round(safety_factor, 2)}", fig
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error in stress analysis: {str(e)}", None
|
| 33 |
|
| 34 |
# Function for Tool Optimization
|
| 35 |
def optimize_tool(speed, feed_rate, depth_of_cut, material):
|
| 36 |
+
try:
|
| 37 |
+
tool_life = 1000 / (speed * feed_rate * depth_of_cut)
|
| 38 |
+
recommended_speed = 0.8 * speed
|
| 39 |
+
recommended_feed_rate = 0.9 * feed_rate
|
| 40 |
+
|
| 41 |
+
return {
|
| 42 |
+
"Estimated Tool Life (hrs)": round(tool_life, 2),
|
| 43 |
+
"Recommended Speed (m/min)": round(recommended_speed, 2),
|
| 44 |
+
"Recommended Feed Rate (mm/rev)": round(recommended_feed_rate, 2)
|
| 45 |
+
}
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return {"Error": str(e)}
|
| 48 |
|
| 49 |
# Gradio interface functions
|
| 50 |
def progressive_die_interface(length, width, thickness):
|