jithenderchoudary commited on
Commit
95ca816
·
verified ·
1 Parent(s): dd03019

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -21
app.py CHANGED
@@ -42,7 +42,7 @@ def visualize_die(length, width, thickness):
42
  return f"Error visualizing die: {str(e)}"
43
 
44
 
45
- # Function for Stress Analysis (including thermal stress and fatigue strength)
46
  def stress_analysis(force, die_width, die_height, material_strength, temperature_change=50, alpha=1e-5, elastic_modulus=200000, fatigue_strength=150):
47
  try:
48
  # Mechanical stress
@@ -86,25 +86,26 @@ def stress_analysis(force, die_width, die_height, material_strength, temperature
86
  return f"Error in stress analysis: {str(e)}", None
87
 
88
 
89
- # Function to generate PDF report
90
- def generate_pdf_report(data, filename="report.pdf"):
 
 
 
91
  try:
92
- c = canvas.Canvas(filename, pagesize=letter)
93
- c.drawString(100, 750, "Simulation Report")
94
- c.drawString(100, 730, f"Max Stress: {data.get('stress', 'N/A')} MPa")
95
- c.drawString(100, 710, f"Safety Factor: {data.get('safety_factor', 'N/A')}")
96
- c.save()
97
- return filename
 
 
 
 
 
 
98
  except Exception as e:
99
- return f"Error generating report: {str(e)}"
100
-
101
-
102
- # Gradio interface functions
103
- def stress_analysis_interface(force, die_width, die_height, material_strength, temperature_change, alpha, elastic_modulus, fatigue_strength):
104
- safety_factor, fig = stress_analysis(force, die_width, die_height, material_strength, temperature_change, alpha, elastic_modulus, fatigue_strength)
105
- data = {"stress": force / (die_width * die_height), "safety_factor": safety_factor}
106
- pdf_filename = generate_pdf_report(data)
107
- return safety_factor, fig, pdf_filename
108
 
109
 
110
  # Create Gradio App
@@ -140,12 +141,25 @@ with gr.Blocks() as app:
140
 
141
  safety_factor_output = gr.Textbox(label="Safety Factor")
142
  stress_chart = gr.Plot()
143
- pdf_file = gr.File(label="Download Report")
144
  stress_button = gr.Button("Analyze Stress")
145
  stress_button.click(
146
- stress_analysis_interface,
147
  inputs=[force, die_width, die_height, material_strength, temperature_change, alpha, elastic_modulus, fatigue_strength],
148
- outputs=[safety_factor_output, stress_chart, pdf_file],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  )
150
 
151
  # Launch the app
 
42
  return f"Error visualizing die: {str(e)}"
43
 
44
 
45
+ # Stress Analysis Function
46
  def stress_analysis(force, die_width, die_height, material_strength, temperature_change=50, alpha=1e-5, elastic_modulus=200000, fatigue_strength=150):
47
  try:
48
  # Mechanical stress
 
86
  return f"Error in stress analysis: {str(e)}", None
87
 
88
 
89
+ # Tool Optimization Function
90
+ def optimize_tool(speed, feed_rate, depth_of_cut, material):
91
+ """
92
+ Optimizes machining parameters for maximum tool life.
93
+ """
94
  try:
95
+ # Simple formula for tool life estimation
96
+ tool_life = 1000 / (speed * feed_rate * depth_of_cut)
97
+
98
+ # Recommend adjustments for better tool life
99
+ recommended_speed = 0.8 * speed
100
+ recommended_feed_rate = 0.9 * feed_rate
101
+
102
+ return {
103
+ "Estimated Tool Life (hrs)": round(tool_life, 2),
104
+ "Recommended Speed (m/min)": round(recommended_speed, 2),
105
+ "Recommended Feed Rate (mm/rev)": round(recommended_feed_rate, 2),
106
+ }
107
  except Exception as e:
108
+ return {"Error": str(e)}
 
 
 
 
 
 
 
 
109
 
110
 
111
  # Create Gradio App
 
141
 
142
  safety_factor_output = gr.Textbox(label="Safety Factor")
143
  stress_chart = gr.Plot()
 
144
  stress_button = gr.Button("Analyze Stress")
145
  stress_button.click(
146
+ lambda f, dw, dh, ms, tc, a, em, fs: stress_analysis(f, dw, dh, ms, tc, a, em, fs),
147
  inputs=[force, die_width, die_height, material_strength, temperature_change, alpha, elastic_modulus, fatigue_strength],
148
+ outputs=[safety_factor_output, stress_chart],
149
+ )
150
+
151
+ with gr.Tab("Tool Optimization"):
152
+ gr.Markdown("### Enter Machining Parameters for Tool Optimization")
153
+ speed = gr.Number(label="Cutting Speed (m/min)", value=100)
154
+ feed_rate = gr.Number(label="Feed Rate (mm/rev)", value=0.2)
155
+ depth_of_cut = gr.Number(label="Depth of Cut (mm)", value=1.0)
156
+ material = gr.Dropdown(choices=["Steel", "Aluminum", "Titanium"], label="Material", value="Steel")
157
+ optimization_results = gr.JSON(label="Optimization Results")
158
+ optimize_button = gr.Button("Optimize Tool")
159
+ optimize_button.click(
160
+ lambda s, fr, dc, m: optimize_tool(s, fr, dc, m),
161
+ inputs=[speed, feed_rate, depth_of_cut, material],
162
+ outputs=optimization_results,
163
  )
164
 
165
  # Launch the app