bvsedev commited on
Commit
8f98f2f
·
verified ·
1 Parent(s): 32c4313

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +286 -0
app.py ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import math
3
+
4
+ # ---------------------------------------------------------------------------
5
+ # Pure calculation functions (ported from @buildvisionai/construction-calculators)
6
+ # GitHub: https://github.com/buildvisionai/construction-calculators
7
+ # ---------------------------------------------------------------------------
8
+
9
+ def calculate_concrete(shape, length, width, radius, depth, units):
10
+ if shape == "Circular":
11
+ volume = math.pi * radius * radius * depth
12
+ else:
13
+ volume = length * width * depth
14
+
15
+ volume_cu_ft = volume * 35.3147 if units == "Metric (m)" else volume
16
+ volume_cu_m = volume if units == "Metric (m)" else volume * 0.0283168
17
+ volume_cu_yd = volume_cu_ft / 27
18
+
19
+ bags = math.ceil(volume / 0.0127) if units == "Metric (m)" else math.ceil(volume / 0.45)
20
+ sand = round(volume * 0.4, 2)
21
+ gravel = round(volume * 0.6, 2)
22
+ water = round(bags * 2.5, 1) if units == "Metric (m)" else round(bags * 0.66, 1)
23
+ water_unit = "liters" if units == "Metric (m)" else "gallons"
24
+
25
+ return (
26
+ f"{volume_cu_yd:.2f} yd³ | {volume_cu_m:.3f} m³ | {volume_cu_ft:.1f} ft³",
27
+ f"{bags} × 60lb bags",
28
+ f"{sand} {'m³' if units == 'Metric (m)' else 'ft³'}",
29
+ f"{gravel} {'m³' if units == 'Metric (m)' else 'ft³'}",
30
+ f"{water} {water_unit}",
31
+ )
32
+
33
+
34
+ PRICE_RANGES = {
35
+ "Asphalt Shingles": (3.5, 5.5),
36
+ "Metal": (7.0, 14.0),
37
+ "Clay/Concrete Tile": (10.0, 20.0),
38
+ "Slate": (15.0, 30.0),
39
+ "Wood Shake": (6.0, 12.0),
40
+ "Flat/TPO": (5.0, 10.0),
41
+ }
42
+ LIFESPAN = {
43
+ "Asphalt Shingles": (15, 30),
44
+ "Metal": (40, 70),
45
+ "Clay/Concrete Tile": (50, 100),
46
+ "Slate": (75, 150),
47
+ "Wood Shake": (20, 40),
48
+ "Flat/TPO": (15, 25),
49
+ }
50
+
51
+ def calculate_roofing_cost(area, units, material, region, pitch_mult, stories_mult, tear_off):
52
+ area_sqft = area * 10.7639 if units == "Metric (m²)" else area
53
+ low, high = PRICE_RANGES[material]
54
+ adj_low = low * region * pitch_mult * stories_mult
55
+ adj_high = high * region * pitch_mult * stories_mult
56
+
57
+ mat_low = adj_low * 0.4 * area_sqft
58
+ mat_high = adj_high * 0.6 * area_sqft
59
+ lab_low = adj_low * 0.4 * area_sqft
60
+ lab_high = adj_high * 0.6 * area_sqft
61
+ tear_low = 1.0 * area_sqft * region if tear_off else 0
62
+ tear_high = 2.0 * area_sqft * region if tear_off else 0
63
+
64
+ total_low = mat_low + lab_low + tear_low
65
+ total_high = mat_high + lab_high + tear_high
66
+
67
+ life_low, life_high = LIFESPAN[material]
68
+ avg_life = (life_low + life_high) / 2
69
+ cpy_low = total_low / avg_life
70
+ cpy_high = total_high / avg_life
71
+
72
+ return (
73
+ f"${mat_low:,.0f} – ${mat_high:,.0f}",
74
+ f"${lab_low:,.0f} – ${lab_high:,.0f}",
75
+ f"${tear_low:,.0f} – ${tear_high:,.0f}" if tear_off else "Not included",
76
+ f"${total_low:,.0f} – ${total_high:,.0f}",
77
+ f"{life_low}–{life_high} years",
78
+ f"${cpy_low:,.0f} – ${cpy_high:,.0f} / year",
79
+ )
80
+
81
+
82
+ PAINT_COVERAGE = {"Standard": 400, "Gloss": 350, "Matte": 450, "Primer": 350}
83
+ PAINT_COVERAGE_M = {"Standard": 10, "Gloss": 8.5, "Matte": 11, "Primer": 8.5}
84
+
85
+ def calculate_paint(length, width, height, doors, windows, ceiling, coats, paint_type, primer, units):
86
+ door_area = 21 if units == "Imperial (ft)" else 1.95
87
+ window_area = 15 if units == "Imperial (ft)" else 1.4
88
+ perimeter = 2 * (length + width)
89
+ wall_area = perimeter * height - doors * door_area - windows * window_area
90
+ wall_area = max(0, wall_area)
91
+ ceil_area = length * width if ceiling else 0
92
+ total_area = (wall_area + ceil_area) * coats
93
+
94
+ coverage = (PAINT_COVERAGE if units == "Imperial (ft)" else PAINT_COVERAGE_M)[paint_type]
95
+ gallons = math.ceil(total_area / coverage)
96
+ primer_gal = math.ceil((wall_area + ceil_area) / coverage) if primer else 0
97
+ cost_low = gallons * 25
98
+ cost_high = gallons * 50
99
+ time_hrs = total_area / (150 if units == "Imperial (ft)" else 14)
100
+
101
+ area_unit = "ft²" if units == "Imperial (ft)" else "m²"
102
+ return (
103
+ f"{wall_area:.1f} {area_unit}",
104
+ f"{ceil_area:.1f} {area_unit}",
105
+ f"{gallons} gallons ({gallons * 4} quarts)",
106
+ f"{primer_gal} gallons" if primer else "Not included",
107
+ f"${cost_low:,.0f} – ${cost_high:,.0f}",
108
+ f"{time_hrs:.1f} hours",
109
+ )
110
+
111
+
112
+ FLOORING_DEFAULTS = {
113
+ "Hardwood": {"cost_min": 6, "cost_max": 12, "box": 20, "box_m": 1.86},
114
+ "Laminate": {"cost_min": 3, "cost_max": 8, "box": 20, "box_m": 1.86},
115
+ "Vinyl Plank": {"cost_min": 2, "cost_max": 7, "box": 20, "box_m": 1.86},
116
+ "Tile": {"cost_min": 5, "cost_max": 15, "box": 10, "box_m": 0.93},
117
+ "Carpet": {"cost_min": 3, "cost_max": 8, "box": 1, "box_m": 1.0 },
118
+ }
119
+
120
+ def calculate_flooring(room_l, room_w, plank_w, plank_l, waste_pct, flooring_type, units):
121
+ total_area = room_l * room_w
122
+ total_with_waste = total_area * (1 + waste_pct / 100)
123
+
124
+ piece_area = (plank_w / 1000) * (plank_l / 1000) if units == "Metric (m)" else (plank_w / 12) * (plank_l / 12)
125
+ pieces = math.ceil(total_with_waste / piece_area)
126
+
127
+ d = FLOORING_DEFAULTS[flooring_type]
128
+ box_cov = d["box_m"] if units == "Metric (m)" else d["box"]
129
+ boxes = math.ceil(total_with_waste / box_cov)
130
+
131
+ area_sqft = total_with_waste * 10.7639 if units == "Metric (m)" else total_with_waste
132
+ cost_low = area_sqft * d["cost_min"]
133
+ cost_high = area_sqft * d["cost_max"]
134
+
135
+ perimeter = 2 * (room_l + room_w)
136
+ transitions = max(1, round(perimeter / 3))
137
+ area_unit = "m²" if units == "Metric (m)" else "ft²"
138
+
139
+ return (
140
+ f"{total_area:.1f} {area_unit}",
141
+ f"{total_with_waste:.1f} {area_unit} (incl. {waste_pct}% waste)",
142
+ f"{pieces} pieces",
143
+ f"{boxes} boxes",
144
+ f"{total_with_waste:.1f} {area_unit}",
145
+ f"{transitions} strips",
146
+ f"${cost_low:,.0f} – ${cost_high:,.0f}",
147
+ )
148
+
149
+
150
+ # ---------------------------------------------------------------------------
151
+ # Gradio UI
152
+ # ---------------------------------------------------------------------------
153
+
154
+ BRAND_FOOTER = """
155
+ <div style="text-align:center; padding: 24px 0 8px; font-size: 14px; color: #6b7280;">
156
+ Powered by <strong><a href="https://buildvisionai.com" target="_blank" style="color:#16a34a;">BuildVision</a></strong>
157
+ — AI-powered construction estimating software &nbsp;|&nbsp;
158
+ <a href="https://buildvisionai.com/calculators" target="_blank" style="color:#16a34a;">26 free live calculators</a>
159
+ &nbsp;|&nbsp;
160
+ <a href="https://github.com/buildvisionai/construction-calculators" target="_blank" style="color:#16a34a;">Open source on GitHub</a>
161
+ &nbsp;|&nbsp;
162
+ <a href="https://www.npmjs.com/package/@buildvisionai/construction-calculators" target="_blank" style="color:#16a34a;">npm package</a>
163
+ </div>
164
+ """
165
+
166
+ with gr.Blocks(
167
+ title="Construction Calculators by BuildVision",
168
+ theme=gr.themes.Soft(primary_hue="green"),
169
+ ) as demo:
170
+
171
+ gr.Markdown("""
172
+ # 🏗️ Construction Calculators
173
+ **Free, instant construction estimating — powered by [BuildVision](https://buildvisionai.com)**
174
+
175
+ Open source calculation library: [GitHub](https://github.com/buildvisionai/construction-calculators) · [npm](https://www.npmjs.com/package/@buildvisionai/construction-calculators) · [26 live calculators](https://buildvisionai.com/calculators)
176
+ """)
177
+
178
+ with gr.Tab("🧱 Concrete"):
179
+ gr.Markdown("Calculate concrete volume, bags, and material requirements. [Live calculator →](https://buildvisionai.com/calculators/concrete-calculator)")
180
+ with gr.Row():
181
+ with gr.Column():
182
+ con_shape = gr.Radio(["Rectangular", "Circular"], value="Rectangular", label="Shape")
183
+ con_units = gr.Radio(["Imperial (ft)", "Metric (m)"], value="Imperial (ft)", label="Units")
184
+ con_length = gr.Number(value=20, label="Length (ft)")
185
+ con_width = gr.Number(value=10, label="Width (ft)")
186
+ con_radius = gr.Number(value=5, label="Radius (ft) — circular only")
187
+ con_depth = gr.Number(value=0.33, label="Depth (ft)")
188
+ con_btn = gr.Button("Calculate", variant="primary")
189
+ with gr.Column():
190
+ con_vol = gr.Textbox(label="Volume")
191
+ con_bags = gr.Textbox(label="Bags Needed")
192
+ con_sand = gr.Textbox(label="Sand")
193
+ con_gravel = gr.Textbox(label="Gravel")
194
+ con_water = gr.Textbox(label="Water")
195
+
196
+ con_btn.click(
197
+ calculate_concrete,
198
+ inputs=[con_shape, con_length, con_width, con_radius, con_depth, con_units],
199
+ outputs=[con_vol, con_bags, con_sand, con_gravel, con_water],
200
+ )
201
+
202
+ with gr.Tab("🏠 Roofing Cost"):
203
+ gr.Markdown("Estimate roofing installation cost by material, region, and pitch. [Live calculator →](https://buildvisionai.com/calculators/roofing-cost-calculator)")
204
+ with gr.Row():
205
+ with gr.Column():
206
+ roof_area = gr.Number(value=2000, label="Roof Area")
207
+ roof_units = gr.Radio(["Imperial (ft²)", "Metric (m²)"], value="Imperial (ft²)", label="Units")
208
+ roof_material = gr.Dropdown(list(PRICE_RANGES.keys()), value="Asphalt Shingles", label="Material")
209
+ roof_region = gr.Slider(0.7, 1.5, value=1.0, step=0.05, label="Regional Cost Multiplier (1.0 = US average)")
210
+ roof_pitch = gr.Slider(1.0, 1.4, value=1.0, step=0.05, label="Pitch Multiplier (1.0 = low, 1.4 = steep)")
211
+ roof_stories = gr.Slider(1.0, 1.5, value=1.0, step=0.1, label="Stories Multiplier")
212
+ roof_tearoff = gr.Checkbox(value=True, label="Include tear-off of existing roof")
213
+ roof_btn = gr.Button("Calculate", variant="primary")
214
+ with gr.Column():
215
+ roof_mat = gr.Textbox(label="Material Cost")
216
+ roof_lab = gr.Textbox(label="Labor Cost")
217
+ roof_tear = gr.Textbox(label="Tear-Off Cost")
218
+ roof_total = gr.Textbox(label="Total Cost")
219
+ roof_life = gr.Textbox(label="Expected Lifespan")
220
+ roof_cpy = gr.Textbox(label="Cost Per Year")
221
+
222
+ roof_btn.click(
223
+ calculate_roofing_cost,
224
+ inputs=[roof_area, roof_units, roof_material, roof_region, roof_pitch, roof_stories, roof_tearoff],
225
+ outputs=[roof_mat, roof_lab, roof_tear, roof_total, roof_life, roof_cpy],
226
+ )
227
+
228
+ with gr.Tab("🎨 Paint"):
229
+ gr.Markdown("Calculate paint gallons, primer, cost, and time for any room. [Live calculator →](https://buildvisionai.com/calculators/paint-calculator)")
230
+ with gr.Row():
231
+ with gr.Column():
232
+ p_units = gr.Radio(["Imperial (ft)", "Metric (m)"], value="Imperial (ft)", label="Units")
233
+ p_length = gr.Number(value=15, label="Room Length")
234
+ p_width = gr.Number(value=12, label="Room Width")
235
+ p_height = gr.Number(value=9, label="Ceiling Height")
236
+ p_doors = gr.Slider(0, 10, value=2, step=1, label="Number of Doors")
237
+ p_windows = gr.Slider(0, 10, value=2, step=1, label="Number of Windows")
238
+ p_ceiling = gr.Checkbox(value=True, label="Include ceiling")
239
+ p_coats = gr.Slider(1, 4, value=2, step=1, label="Number of Coats")
240
+ p_type = gr.Dropdown(["Standard", "Gloss", "Matte"], value="Standard", label="Paint Type")
241
+ p_primer = gr.Checkbox(value=True, label="Include primer coat")
242
+ p_btn = gr.Button("Calculate", variant="primary")
243
+ with gr.Column():
244
+ p_wall = gr.Textbox(label="Net Wall Area")
245
+ p_ceil = gr.Textbox(label="Ceiling Area")
246
+ p_gal = gr.Textbox(label="Paint Needed")
247
+ p_prim = gr.Textbox(label="Primer Needed")
248
+ p_cost = gr.Textbox(label="Estimated Cost")
249
+ p_time = gr.Textbox(label="Time Estimate")
250
+
251
+ p_btn.click(
252
+ calculate_paint,
253
+ inputs=[p_length, p_width, p_height, p_doors, p_windows, p_ceiling, p_coats, p_type, p_primer, p_units],
254
+ outputs=[p_wall, p_ceil, p_gal, p_prim, p_cost, p_time],
255
+ )
256
+
257
+ with gr.Tab("🪵 Flooring"):
258
+ gr.Markdown("Calculate flooring planks, boxes, underlayment, and installed cost. [Live calculator →](https://buildvisionai.com/calculators/flooring-calculator)")
259
+ with gr.Row():
260
+ with gr.Column():
261
+ f_units = gr.Radio(["Imperial (ft)", "Metric (m)"], value="Imperial (ft)", label="Units")
262
+ f_room_l = gr.Number(value=15, label="Room Length")
263
+ f_room_w = gr.Number(value=12, label="Room Width")
264
+ f_plank_w = gr.Number(value=5, label="Plank Width (in / mm)")
265
+ f_plank_l = gr.Number(value=48, label="Plank Length (in / mm)")
266
+ f_waste = gr.Slider(5, 20, value=10, step=1, label="Waste % (10% recommended)")
267
+ f_type = gr.Dropdown(list(FLOORING_DEFAULTS.keys()), value="Hardwood", label="Flooring Type")
268
+ f_btn = gr.Button("Calculate", variant="primary")
269
+ with gr.Column():
270
+ f_area = gr.Textbox(label="Room Area")
271
+ f_waste_a = gr.Textbox(label="Area with Waste")
272
+ f_pieces = gr.Textbox(label="Pieces Needed")
273
+ f_boxes = gr.Textbox(label="Boxes Needed")
274
+ f_under = gr.Textbox(label="Underlayment Area")
275
+ f_trans = gr.Textbox(label="Transition Strips")
276
+ f_cost = gr.Textbox(label="Installed Cost Range")
277
+
278
+ f_btn.click(
279
+ calculate_flooring,
280
+ inputs=[f_room_l, f_room_w, f_plank_w, f_plank_l, f_waste, f_type, f_units],
281
+ outputs=[f_area, f_waste_a, f_pieces, f_boxes, f_under, f_trans, f_cost],
282
+ )
283
+
284
+ gr.HTML(BRAND_FOOTER)
285
+
286
+ demo.launch()