UsmanGoraya commited on
Commit
4427c88
·
verified ·
1 Parent(s): 29d58ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -94,21 +94,23 @@ def estimate(rooms, wall_thickness, openings, floors):
94
  }
95
 
96
  def draw_plan_image(room_shapes):
97
- fig, ax = plt.subplots()
98
  for x0, y0, x1, y1 in room_shapes:
99
  width = x1 - x0
100
  height = y1 - y0
101
- rect = patches.Rectangle((x0, y0), width, height, linewidth=1, edgecolor='black', facecolor='none')
102
  ax.add_patch(rect)
103
- ax.text(x0 + width / 2, y0 - 2, f"{round(width / 12, 1)} ft", ha='center', fontsize=8)
104
- ax.text(x1 + 2, y0 + height / 2, f"{round(height / 12, 1)} ft", va='center', fontsize=8, rotation=90)
 
105
  ax.set_aspect('equal')
106
  ax.axis('off')
107
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
108
- fig.savefig(temp_file.name, bbox_inches='tight')
109
  plt.close(fig)
110
  return temp_file.name
111
 
 
112
  def generate_pdf(data_dict, calc_details, room_shapes):
113
  image_path = draw_plan_image(room_shapes)
114
 
@@ -144,12 +146,14 @@ def generate_pdf(data_dict, calc_details, room_shapes):
144
 
145
  pdf.ln(5)
146
  pdf.set_font("Arial", 'B', size=12)
147
- pdf.cell(200, 10, "2D Plan with Dimensions (in ft)", ln=True)
148
- pdf.image(image_path, x=10, y=None, w=180)
 
 
 
 
 
149
 
150
- tmp = NamedTemporaryFile(delete=False, suffix=".pdf")
151
- pdf.output(tmp.name)
152
- return tmp.name
153
 
154
  def plot_rooms(shapes):
155
  fig, ax = plt.subplots()
 
94
  }
95
 
96
  def draw_plan_image(room_shapes):
97
+ fig, ax = plt.subplots(figsize=(8, 6))
98
  for x0, y0, x1, y1 in room_shapes:
99
  width = x1 - x0
100
  height = y1 - y0
101
+ rect = patches.Rectangle((x0, y0), width, height, linewidth=1.5, edgecolor='black', facecolor='none')
102
  ax.add_patch(rect)
103
+ ax.text(x0 + width / 2, y0 - 5, f"{round(width / 12, 1)} ft", ha='center', fontsize=9)
104
+ ax.text(x1 + 2, y0 + height / 2, f"{round(height / 12, 1)} ft", va='center', fontsize=9, rotation=90)
105
+ ax.set_title("2D Room Layout with Dimensions")
106
  ax.set_aspect('equal')
107
  ax.axis('off')
108
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
109
+ fig.savefig(temp_file.name, bbox_inches='tight', dpi=150)
110
  plt.close(fig)
111
  return temp_file.name
112
 
113
+
114
  def generate_pdf(data_dict, calc_details, room_shapes):
115
  image_path = draw_plan_image(room_shapes)
116
 
 
146
 
147
  pdf.ln(5)
148
  pdf.set_font("Arial", 'B', size=12)
149
+ pdf.cell(200, 10, "📐 2D Plan with Dimensions (in feet)", ln=True)
150
+
151
+ try:
152
+ pdf.image(image_path, x=10, y=None, w=180)
153
+ except Exception as e:
154
+ pdf.set_font("Arial", '', size=10)
155
+ pdf.cell(200, 10, f"Error embedding plan image: {e}", ln=True)
156
 
 
 
 
157
 
158
  def plot_rooms(shapes):
159
  fig, ax = plt.subplots()