Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,16 @@ import gradio as gr
|
|
| 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}. You can download the file."
|
| 15 |
except Exception as e:
|
| 16 |
return f"Error generating die: {str(e)}"
|
|
@@ -18,17 +23,19 @@ def generate_die(length, width, thickness):
|
|
| 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 |
-
|
| 29 |
plt.tight_layout() # Ensure the plot is displayed correctly
|
| 30 |
plt.close(fig) # Close the plot so it doesn't render twice
|
| 31 |
|
|
|
|
| 32 |
return f"Safety Factor: {round(safety_factor, 2)}", fig
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error in stress analysis: {str(e)}", None
|
|
@@ -36,10 +43,12 @@ def stress_analysis(force, die_width, die_height, material_strength):
|
|
| 36 |
# Function for Tool Optimization
|
| 37 |
def optimize_tool(speed, feed_rate, depth_of_cut, material):
|
| 38 |
try:
|
|
|
|
| 39 |
tool_life = 1000 / (speed * feed_rate * depth_of_cut)
|
| 40 |
recommended_speed = 0.8 * speed
|
| 41 |
recommended_feed_rate = 0.9 * feed_rate
|
| 42 |
|
|
|
|
| 43 |
return {
|
| 44 |
"Estimated Tool Life (hrs)": round(tool_life, 2),
|
| 45 |
"Recommended Speed (m/min)": round(recommended_speed, 2),
|
|
@@ -64,6 +73,7 @@ with gr.Blocks() as app:
|
|
| 64 |
gr.Markdown("Select a tool below to get started:")
|
| 65 |
|
| 66 |
with gr.Tabs():
|
|
|
|
| 67 |
with gr.Tab("Progressive Die Design"):
|
| 68 |
gr.Markdown("### Enter Dimensions for Progressive Die")
|
| 69 |
length = gr.Number(label="Length (mm)", value=100)
|
|
@@ -73,6 +83,7 @@ with gr.Blocks() as app:
|
|
| 73 |
die_button = gr.Button("Generate Die")
|
| 74 |
die_button.click(progressive_die_interface, inputs=[length, width, thickness], outputs=die_output)
|
| 75 |
|
|
|
|
| 76 |
with gr.Tab("Stress Analysis"):
|
| 77 |
gr.Markdown("### Enter Parameters for Stress Analysis")
|
| 78 |
force = gr.Number(label="Force (N)", value=10000)
|
|
@@ -84,6 +95,7 @@ with gr.Blocks() as app:
|
|
| 84 |
stress_button = gr.Button("Analyze Stress")
|
| 85 |
stress_button.click(stress_analysis_interface, inputs=[force, die_width, die_height, material_strength], outputs=[safety_factor_output, stress_chart])
|
| 86 |
|
|
|
|
| 87 |
with gr.Tab("Tool Optimization"):
|
| 88 |
gr.Markdown("### Enter Machining Parameters for Tool Optimization")
|
| 89 |
speed = gr.Number(label="Cutting Speed (m/min)", value=100)
|
|
|
|
| 6 |
# Function for Progressive Die Design
|
| 7 |
def generate_die(length, width, thickness):
|
| 8 |
try:
|
| 9 |
+
# Generate the die design
|
| 10 |
plate = cq.Workplane("XY").box(length, width, thickness)
|
| 11 |
punch = cq.Workplane("XY").rect(10, 10).extrude(5).translate((length/4, width/4, thickness/2))
|
| 12 |
die = plate.cut(punch)
|
| 13 |
+
|
| 14 |
+
# Save the die to a file
|
| 15 |
filename = "progressive_die.step"
|
| 16 |
cq.exporters.export(die, filename)
|
| 17 |
+
|
| 18 |
+
# Return success message
|
| 19 |
return f"Progressive die design saved as {filename}. You can download the file."
|
| 20 |
except Exception as e:
|
| 21 |
return f"Error generating die: {str(e)}"
|
|
|
|
| 23 |
# Function for Stress Analysis
|
| 24 |
def stress_analysis(force, die_width, die_height, material_strength):
|
| 25 |
try:
|
| 26 |
+
# Calculate stress and safety factor
|
| 27 |
stress = force / (die_width * die_height)
|
| 28 |
safety_factor = material_strength / stress
|
| 29 |
|
| 30 |
+
# Create stress analysis plot
|
| 31 |
fig, ax = plt.subplots()
|
| 32 |
ax.bar(["Stress", "Material Strength"], [stress, material_strength])
|
| 33 |
ax.set_ylabel("Stress (MPa)")
|
| 34 |
ax.set_title("Stress Analysis")
|
|
|
|
| 35 |
plt.tight_layout() # Ensure the plot is displayed correctly
|
| 36 |
plt.close(fig) # Close the plot so it doesn't render twice
|
| 37 |
|
| 38 |
+
# Return the results and plot
|
| 39 |
return f"Safety Factor: {round(safety_factor, 2)}", fig
|
| 40 |
except Exception as e:
|
| 41 |
return f"Error in stress analysis: {str(e)}", None
|
|
|
|
| 43 |
# Function for Tool Optimization
|
| 44 |
def optimize_tool(speed, feed_rate, depth_of_cut, material):
|
| 45 |
try:
|
| 46 |
+
# Estimate tool life and recommend adjustments
|
| 47 |
tool_life = 1000 / (speed * feed_rate * depth_of_cut)
|
| 48 |
recommended_speed = 0.8 * speed
|
| 49 |
recommended_feed_rate = 0.9 * feed_rate
|
| 50 |
|
| 51 |
+
# Return optimization results
|
| 52 |
return {
|
| 53 |
"Estimated Tool Life (hrs)": round(tool_life, 2),
|
| 54 |
"Recommended Speed (m/min)": round(recommended_speed, 2),
|
|
|
|
| 73 |
gr.Markdown("Select a tool below to get started:")
|
| 74 |
|
| 75 |
with gr.Tabs():
|
| 76 |
+
# Tab for Progressive Die Design
|
| 77 |
with gr.Tab("Progressive Die Design"):
|
| 78 |
gr.Markdown("### Enter Dimensions for Progressive Die")
|
| 79 |
length = gr.Number(label="Length (mm)", value=100)
|
|
|
|
| 83 |
die_button = gr.Button("Generate Die")
|
| 84 |
die_button.click(progressive_die_interface, inputs=[length, width, thickness], outputs=die_output)
|
| 85 |
|
| 86 |
+
# Tab for Stress Analysis
|
| 87 |
with gr.Tab("Stress Analysis"):
|
| 88 |
gr.Markdown("### Enter Parameters for Stress Analysis")
|
| 89 |
force = gr.Number(label="Force (N)", value=10000)
|
|
|
|
| 95 |
stress_button = gr.Button("Analyze Stress")
|
| 96 |
stress_button.click(stress_analysis_interface, inputs=[force, die_width, die_height, material_strength], outputs=[safety_factor_output, stress_chart])
|
| 97 |
|
| 98 |
+
# Tab for Tool Optimization
|
| 99 |
with gr.Tab("Tool Optimization"):
|
| 100 |
gr.Markdown("### Enter Machining Parameters for Tool Optimization")
|
| 101 |
speed = gr.Number(label="Cutting Speed (m/min)", value=100)
|