karthikmn commited on
Commit
be876fe
·
verified ·
1 Parent(s): bde8120

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -2,6 +2,11 @@ import cadquery as cq
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  import gradio as gr
 
 
 
 
 
5
 
6
  # Function for Progressive Die Design
7
  def generate_die(length, width, thickness):
@@ -12,17 +17,21 @@ def generate_die(length, width, thickness):
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)}"
22
 
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
@@ -43,8 +52,10 @@ def stress_analysis(force, die_width, die_height, material_strength):
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
 
 
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  import gradio as gr
5
+ import os
6
+
7
+ # Ensure there's a directory for saving files
8
+ if not os.path.exists("generated_files"):
9
+ os.makedirs("generated_files")
10
 
11
  # Function for Progressive Die Design
12
  def generate_die(length, width, thickness):
 
17
  die = plate.cut(punch)
18
 
19
  # Save the die to a file
20
+ filename = "generated_files/progressive_die.step"
21
  cq.exporters.export(die, filename)
22
 
23
+ # Return success message and file path for download
24
+ return f"Progressive die design saved. [Download the file](/{filename})"
25
  except Exception as e:
26
  return f"Error generating die: {str(e)}"
27
 
28
  # Function for Stress Analysis
29
  def stress_analysis(force, die_width, die_height, material_strength):
30
  try:
31
+ # Validate inputs to avoid invalid calculations
32
+ if force <= 0 or die_width <= 0 or die_height <= 0 or material_strength <= 0:
33
+ return "All values must be positive."
34
+
35
  # Calculate stress and safety factor
36
  stress = force / (die_width * die_height)
37
  safety_factor = material_strength / stress
 
52
  # Function for Tool Optimization
53
  def optimize_tool(speed, feed_rate, depth_of_cut, material):
54
  try:
55
+ # Adjust tool life estimate based on material
56
+ material_factor = {"Steel": 1.0, "Aluminum": 0.8, "Titanium": 1.2}
57
+ tool_life = 1000 / (speed * feed_rate * depth_of_cut * material_factor.get(material, 1.0))
58
+
59
  recommended_speed = 0.8 * speed
60
  recommended_feed_rate = 0.9 * feed_rate
61