karthikmn commited on
Commit
fa7d324
·
verified ·
1 Parent(s): 9e4bb35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -1,13 +1,13 @@
1
  import gradio as gr
2
- import numpy as np
3
  import matplotlib.pyplot as plt
 
4
  import logging
5
 
6
  # Configure logging
7
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
8
  logger = logging.getLogger()
9
 
10
- # Function to generate the die design visualization (simulated)
11
  def generate_die_ANSYS(length, width, thickness, die_shape):
12
  try:
13
  # Log inputs
@@ -18,11 +18,11 @@ def generate_die_ANSYS(length, width, thickness, die_shape):
18
  logger.error("Dimensions must be greater than zero.")
19
  return "Error: Dimensions must be greater than zero.", None
20
 
21
- # Simulating die design generation based on shape
22
- fig, ax = plt.subplots(figsize=(6, 6))
23
 
24
  if die_shape == "Rectangle":
25
- # Visualize a rectangular die (simulated)
26
  ax.add_patch(plt.Rectangle((0, 0), length, width, linewidth=2, edgecolor='blue', facecolor='cyan', label='Rectangle Die'))
27
  ax.set_xlim(0, length + 20)
28
  ax.set_ylim(0, width + 20)
@@ -30,7 +30,7 @@ def generate_die_ANSYS(length, width, thickness, die_shape):
30
  logger.info(f"Created rectangular die with dimensions {length} x {width}.")
31
 
32
  elif die_shape == "Circle":
33
- # Visualize a circular die (simulated)
34
  circle = plt.Circle((length / 2, width / 2), radius=min(length, width) / 2, color='orange', ec='black', lw=2, label='Circular Die')
35
  ax.add_patch(circle)
36
  ax.set_xlim(0, length + 20)
@@ -38,6 +38,39 @@ def generate_die_ANSYS(length, width, thickness, die_shape):
38
  ax.set_title(f"Progressive Die Design - Circle {length}x{width}")
39
  logger.info(f"Created circular die with diameter {length} and width {width}.")
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  ax.set_xlabel("X Dimension (mm)")
42
  ax.set_ylabel("Y Dimension (mm)")
43
  ax.legend(loc="upper right")
@@ -78,7 +111,7 @@ with gr.Blocks() as app:
78
  width = gr.Number(label="Width (mm)", value=50)
79
  thickness = gr.Number(label="Thickness (mm)", value=10)
80
 
81
- die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle"], value="Rectangle")
82
  die_button = gr.Button("Generate Die Design")
83
  die_output = gr.Textbox(label="Die Design Message", interactive=False)
84
  die_download = gr.File(label="Download Die Design Image")
 
1
  import gradio as gr
 
2
  import matplotlib.pyplot as plt
3
+ import numpy as np
4
  import logging
5
 
6
  # Configure logging
7
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
8
  logger = logging.getLogger()
9
 
10
+ # Function to generate the die design visualization (with more shapes)
11
  def generate_die_ANSYS(length, width, thickness, die_shape):
12
  try:
13
  # Log inputs
 
18
  logger.error("Dimensions must be greater than zero.")
19
  return "Error: Dimensions must be greater than zero.", None
20
 
21
+ # Simulate a realistic die design with multiple shapes
22
+ fig, ax = plt.subplots(figsize=(8, 8))
23
 
24
  if die_shape == "Rectangle":
25
+ # Visualize a rectangular die
26
  ax.add_patch(plt.Rectangle((0, 0), length, width, linewidth=2, edgecolor='blue', facecolor='cyan', label='Rectangle Die'))
27
  ax.set_xlim(0, length + 20)
28
  ax.set_ylim(0, width + 20)
 
30
  logger.info(f"Created rectangular die with dimensions {length} x {width}.")
31
 
32
  elif die_shape == "Circle":
33
+ # Visualize a circular die
34
  circle = plt.Circle((length / 2, width / 2), radius=min(length, width) / 2, color='orange', ec='black', lw=2, label='Circular Die')
35
  ax.add_patch(circle)
36
  ax.set_xlim(0, length + 20)
 
38
  ax.set_title(f"Progressive Die Design - Circle {length}x{width}")
39
  logger.info(f"Created circular die with diameter {length} and width {width}.")
40
 
41
+ elif die_shape == "Ellipse":
42
+ # Visualize an elliptical die
43
+ ellipse = plt.Ellipse((length / 2, width / 2), width, length, color='green', ec='black', lw=2, label='Elliptical Die')
44
+ ax.add_patch(ellipse)
45
+ ax.set_xlim(0, length + 20)
46
+ ax.set_ylim(0, width + 20)
47
+ ax.set_title(f"Progressive Die Design - Ellipse {length}x{width}")
48
+ logger.info(f"Created elliptical die with dimensions {length} x {width}.")
49
+
50
+ elif die_shape == "Hexagon":
51
+ # Visualize a hexagonal die
52
+ angle = np.linspace(0, 2 * np.pi, 7)
53
+ x = length / 2 * np.cos(angle) + length / 2
54
+ y = width / 2 * np.sin(angle) + width / 2
55
+ ax.fill(x, y, color='purple', edgecolor='black', lw=2, label='Hexagonal Die')
56
+ ax.set_xlim(0, length + 20)
57
+ ax.set_ylim(0, width + 20)
58
+ ax.set_title(f"Progressive Die Design - Hexagon {length}x{width}")
59
+ logger.info(f"Created hexagonal die with side length {length}.")
60
+
61
+ elif die_shape == "Polygon":
62
+ # Visualize a polygonal die (random polygon with 5 sides)
63
+ num_sides = 5
64
+ angle = np.linspace(0, 2 * np.pi, num_sides + 1)
65
+ radius = min(length, width) / 2
66
+ x = radius * np.cos(angle) + length / 2
67
+ y = radius * np.sin(angle) + width / 2
68
+ ax.fill(x, y, color='red', edgecolor='black', lw=2, label='Polygonal Die')
69
+ ax.set_xlim(0, length + 20)
70
+ ax.set_ylim(0, width + 20)
71
+ ax.set_title(f"Progressive Die Design - Polygon {length}x{width}")
72
+ logger.info(f"Created polygonal die with {num_sides} sides.")
73
+
74
  ax.set_xlabel("X Dimension (mm)")
75
  ax.set_ylabel("Y Dimension (mm)")
76
  ax.legend(loc="upper right")
 
111
  width = gr.Number(label="Width (mm)", value=50)
112
  thickness = gr.Number(label="Thickness (mm)", value=10)
113
 
114
+ die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle", "Ellipse", "Hexagon", "Polygon"], value="Rectangle")
115
  die_button = gr.Button("Generate Die Design")
116
  die_output = gr.Textbox(label="Die Design Message", interactive=False)
117
  die_download = gr.File(label="Download Die Design Image")