UsmanGoraya commited on
Commit
ccd182c
·
verified ·
1 Parent(s): 85e3807

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py CHANGED
@@ -1,3 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def estimate_quantities(plan_data, section_data):
2
  items = []
3
 
@@ -107,3 +144,27 @@ def estimate_quantities(plan_data, section_data):
107
 
108
  df = pd.DataFrame(items)
109
  return df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import ezdxf
3
+ import tempfile
4
+ import pandas as pd
5
+ import os
6
+
7
+ # ---------- Function to extract data from DXF ----------
8
+ def extract_entities(uploaded_file):
9
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".dxf") as tmp:
10
+ tmp.write(uploaded_file.read())
11
+ tmp_path = tmp.name
12
+
13
+ doc = ezdxf.readfile(tmp_path)
14
+ msp = doc.modelspace()
15
+
16
+ plan_data = {"rooms": [], "doors": [], "windows": []}
17
+ section_data = {"slabs": [], "beams": [], "columns": []}
18
+
19
+ for e in msp:
20
+ if e.dxftype() == "LWPOLYLINE" and "plan" in e.dxf.layer.lower():
21
+ points = e.get_points()
22
+ plan_data["rooms"].append({"points": points})
23
+ elif e.dxftype() == "LINE" and "door" in e.dxf.layer.lower():
24
+ plan_data["doors"].append({"start": e.dxf.start, "end": e.dxf.end})
25
+ elif e.dxftype() == "LINE" and "window" in e.dxf.layer.lower():
26
+ plan_data["windows"].append({"start": e.dxf.start, "end": e.dxf.end})
27
+ elif "section" in e.dxf.layer.lower():
28
+ if "slab" in e.dxf.layer.lower():
29
+ section_data["slabs"].append(e)
30
+ elif "beam" in e.dxf.layer.lower():
31
+ section_data["beams"].append(e)
32
+ elif "column" in e.dxf.layer.lower():
33
+ section_data["columns"].append(e)
34
+
35
+ return plan_data, section_data
36
+
37
+ # ---------- Function to estimate quantities ----------
38
  def estimate_quantities(plan_data, section_data):
39
  items = []
40
 
 
144
 
145
  df = pd.DataFrame(items)
146
  return df
147
+
148
+ # ---------- Streamlit App UI ----------
149
+ st.set_page_config(layout="centered")
150
+ st.title("🏗️ AutoCAD Drawing Estimator (AU Standards)")
151
+
152
+ uploaded_file = st.file_uploader("Upload AutoCAD DXF File", type=["dxf"])
153
+
154
+ if uploaded_file:
155
+ with st.spinner("Reading and analyzing the drawing..."):
156
+ try:
157
+ plan_data, section_data = extract_entities(uploaded_file)
158
+ df = estimate_quantities(plan_data, section_data)
159
+
160
+ st.success("✅ Drawing processed and estimate generated.")
161
+ st.dataframe(df)
162
+
163
+ output_path = "Construction_Estimate.xlsx"
164
+ df.to_excel(output_path, index=False)
165
+
166
+ with open(output_path, "rb") as f:
167
+ st.download_button("📥 Download Estimate (Excel)", f, file_name=output_path)
168
+
169
+ except Exception as e:
170
+ st.error(f"Error processing file: {e}")