Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 fitz # PyMuPDF
|
| 9 |
+
import re
|
| 10 |
+
|
| 11 |
+
# Constants
|
| 12 |
+
BRICK_VOLUME_CFT = (9/12) * (4.5/12) * (3/12) # in cft
|
| 13 |
+
CEMENT_SAND_RATIO = 1 / 6
|
| 14 |
+
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="Smart Estimator", page_icon="📐")
|
| 19 |
+
st.title("📐 Smart Quantity Estimator from Building Layout PDF")
|
| 20 |
+
|
| 21 |
+
uploaded_pdf = st.file_uploader("Upload your house layout PDF", type=["pdf"])
|
| 22 |
+
|
| 23 |
+
def extract_text_from_pdf(file):
|
| 24 |
+
doc = fitz.open(stream=file.read(), filetype="pdf")
|
| 25 |
+
text = ""
|
| 26 |
+
for page in doc:
|
| 27 |
+
text += page.get_text()
|
| 28 |
+
return text
|
| 29 |
+
|
| 30 |
+
def parse_dimensions(text):
|
| 31 |
+
rooms = re.findall(r'Room:\s*(\d+\.?\d*)x(\d+\.?\d*)x(\d+\.?\d*)\s*ft', text)
|
| 32 |
+
wall_thickness = re.search(r'Wall Thickness:\s*(\d+\.?\d*)\s*ft', text)
|
| 33 |
+
openings = re.findall(r'(Door|Window|Opening):\s*(\d+\.?\d*)x(\d+\.?\d*)\s*ft', text)
|
| 34 |
+
beams = 'Beams: Yes' in text
|
| 35 |
+
|
| 36 |
+
return {
|
| 37 |
+
"rooms": [(float(l), float(w), float(h)) for l, w, h in rooms],
|
| 38 |
+
"wall_thickness": float(wall_thickness.group(1)) if wall_thickness else 0.75,
|
| 39 |
+
"openings": [(typ, float(l), float(h)) for typ, l, h in openings],
|
| 40 |
+
"has_beams": beams
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
def estimate(rooms, wall_thickness, openings, has_beams):
|
| 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 |
+
if has_beams:
|
| 53 |
+
for _, l, _ in openings:
|
| 54 |
+
beam_len = l + 1 # add 1ft
|
| 55 |
+
beam_volume += beam_len * 0.75 * 0.75
|
| 56 |
+
|
| 57 |
+
net_volume = wall_volume - opening_volume - beam_volume
|
| 58 |
+
|
| 59 |
+
number_of_bricks = round((net_volume / BRICK_VOLUME_CFT) * 1.05)
|
| 60 |
+
mortar_volume = net_volume * 0.25
|
| 61 |
+
cement_volume = mortar_volume * CEMENT_SAND_RATIO
|
| 62 |
+
sand_volume = mortar_volume * SAND_RATIO
|
| 63 |
+
|
| 64 |
+
cement_bag_volume_cft = CEMENT_BAG_WEIGHT_KG / CEMENT_DENSITY_KG_PER_CFT
|
| 65 |
+
cement_bags = round(cement_volume / cement_bag_volume_cft)
|
| 66 |
+
|
| 67 |
+
return number_of_bricks, sand_volume, cement_bags
|
| 68 |
+
|
| 69 |
+
if uploaded_pdf:
|
| 70 |
+
text = extract_text_from_pdf(uploaded_pdf)
|
| 71 |
+
st.text_area("📄 Extracted Text", text, height=300)
|
| 72 |
+
|
| 73 |
+
data = parse_dimensions(text)
|
| 74 |
+
|
| 75 |
+
if data["rooms"]:
|
| 76 |
+
bricks, sand, cement = estimate(data["rooms"], data["wall_thickness"], data["openings"], data["has_beams"])
|
| 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 dimensions found in the PDF. Please make sure your format is correct.")
|