Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
-
Room: 15x12x10 ft
|
| 2 |
-
Wall Thickness: 0.75 ft
|
| 3 |
-
Openings:
|
| 4 |
-
- Door: 3x7 ft
|
| 5 |
-
- Window: 4x4 ft
|
| 6 |
-
Beams: Yes
|
| 7 |
import streamlit as st
|
| 8 |
-
import
|
| 9 |
-
import
|
| 10 |
|
| 11 |
# Constants
|
| 12 |
BRICK_VOLUME_CFT = (9/12) * (4.5/12) * (3/12) # in cft
|
|
@@ -15,44 +9,57 @@ SAND_RATIO = 5 / 6
|
|
| 15 |
CEMENT_DENSITY_KG_PER_CFT = 1440 / 35.3147
|
| 16 |
CEMENT_BAG_WEIGHT_KG = 50
|
| 17 |
|
| 18 |
-
st.set_page_config(page_title="
|
| 19 |
-
st.title("📐
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def
|
| 24 |
-
doc =
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
wall_volume = 0
|
| 45 |
for length, width, height in rooms:
|
| 46 |
wall_area = 2 * (length + width) * height
|
| 47 |
wall_volume += wall_area * wall_thickness
|
| 48 |
|
| 49 |
opening_volume = sum(l * h * wall_thickness for _, l, h in openings)
|
| 50 |
-
|
| 51 |
beam_volume = 0
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
beam_volume += beam_len * 0.75 * 0.75
|
| 56 |
|
| 57 |
net_volume = wall_volume - opening_volume - beam_volume
|
| 58 |
|
|
@@ -66,18 +73,24 @@ def estimate(rooms, wall_thickness, openings, has_beams):
|
|
| 66 |
|
| 67 |
return number_of_bricks, sand_volume, cement_bags
|
| 68 |
|
| 69 |
-
if
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
st.subheader("📊 Estimated Quantities:")
|
| 79 |
st.write(f"🧱 **Bricks Needed:** {bricks:,} bricks")
|
| 80 |
st.write(f"🏖️ **Sand Needed:** {sand:.2f} cft")
|
| 81 |
st.write(f"🪣 **Cement Needed:** {cement} bags (50kg each)")
|
| 82 |
else:
|
| 83 |
-
st.warning("No room
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import ezdxf
|
| 3 |
+
import io
|
| 4 |
|
| 5 |
# Constants
|
| 6 |
BRICK_VOLUME_CFT = (9/12) * (4.5/12) * (3/12) # in cft
|
|
|
|
| 9 |
CEMENT_DENSITY_KG_PER_CFT = 1440 / 35.3147
|
| 10 |
CEMENT_BAG_WEIGHT_KG = 50
|
| 11 |
|
| 12 |
+
st.set_page_config(page_title="CAD-based Quantity Estimator", page_icon="📐")
|
| 13 |
+
st.title("📐 Brick, Cement & Sand Estimation from AutoCAD (.dxf)")
|
| 14 |
+
|
| 15 |
+
uploaded_file = st.file_uploader("Upload your .dxf AutoCAD file", type=["dxf"])
|
| 16 |
+
|
| 17 |
+
def extract_from_dxf(file):
|
| 18 |
+
doc = ezdxf.read(file)
|
| 19 |
+
msp = doc.modelspace()
|
| 20 |
+
|
| 21 |
+
rooms = []
|
| 22 |
+
wall_thickness = 0.75 # Default
|
| 23 |
+
openings = []
|
| 24 |
+
|
| 25 |
+
for entity in msp:
|
| 26 |
+
if entity.dxftype() == "TEXT":
|
| 27 |
+
content = entity.dxf.text.lower()
|
| 28 |
+
if "room" in content and "x" in content:
|
| 29 |
+
try:
|
| 30 |
+
dims = content.split(":")[1].strip().split("x")
|
| 31 |
+
l, w, h = map(float, dims)
|
| 32 |
+
rooms.append((l, w, h))
|
| 33 |
+
except:
|
| 34 |
+
continue
|
| 35 |
+
elif "wall thickness" in content:
|
| 36 |
+
try:
|
| 37 |
+
wt = float(content.split(":")[1].strip())
|
| 38 |
+
wall_thickness = wt
|
| 39 |
+
except:
|
| 40 |
+
continue
|
| 41 |
+
elif any(x in content for x in ["door", "window", "opening"]):
|
| 42 |
+
try:
|
| 43 |
+
dims = content.split(":")[1].strip().split("x")
|
| 44 |
+
l, h = map(float, dims)
|
| 45 |
+
openings.append(("opening", l, h))
|
| 46 |
+
except:
|
| 47 |
+
continue
|
| 48 |
+
|
| 49 |
+
return rooms, wall_thickness, openings
|
| 50 |
+
|
| 51 |
+
def estimate(rooms, wall_thickness, openings):
|
| 52 |
wall_volume = 0
|
| 53 |
for length, width, height in rooms:
|
| 54 |
wall_area = 2 * (length + width) * height
|
| 55 |
wall_volume += wall_area * wall_thickness
|
| 56 |
|
| 57 |
opening_volume = sum(l * h * wall_thickness for _, l, h in openings)
|
| 58 |
+
|
| 59 |
beam_volume = 0
|
| 60 |
+
for _, l, _ in openings:
|
| 61 |
+
beam_len = l + 1 # add 1ft
|
| 62 |
+
beam_volume += beam_len * 0.75 * 0.75
|
|
|
|
| 63 |
|
| 64 |
net_volume = wall_volume - opening_volume - beam_volume
|
| 65 |
|
|
|
|
| 73 |
|
| 74 |
return number_of_bricks, sand_volume, cement_bags
|
| 75 |
|
| 76 |
+
if uploaded_file:
|
| 77 |
+
st.success("✅ File uploaded. Parsing...")
|
| 78 |
+
rooms, wall_thickness, openings = extract_from_dxf(io.BytesIO(uploaded_file.read()))
|
| 79 |
|
| 80 |
+
if rooms:
|
| 81 |
+
st.write(f"🧱 Rooms Detected: {len(rooms)}")
|
| 82 |
+
for i, r in enumerate(rooms, 1):
|
| 83 |
+
st.write(f"Room {i}: {r[0]}x{r[1]}x{r[2]} ft")
|
| 84 |
|
| 85 |
+
st.write(f"📏 Wall Thickness: {wall_thickness} ft")
|
| 86 |
+
st.write(f"🚪 Openings Detected: {len(openings)}")
|
| 87 |
+
|
| 88 |
+
bricks, sand, cement = estimate(rooms, wall_thickness, openings)
|
| 89 |
|
| 90 |
st.subheader("📊 Estimated Quantities:")
|
| 91 |
st.write(f"🧱 **Bricks Needed:** {bricks:,} bricks")
|
| 92 |
st.write(f"🏖️ **Sand Needed:** {sand:.2f} cft")
|
| 93 |
st.write(f"🪣 **Cement Needed:** {cement} bags (50kg each)")
|
| 94 |
else:
|
| 95 |
+
st.warning("No room data found. Please check the .dxf text format.")
|
| 96 |
+
|