Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,9 +21,15 @@ uploaded_file = st.file_uploader("Upload your DXF file", type=["dxf"])
|
|
| 21 |
|
| 22 |
@st.cache_data
|
| 23 |
def extract_geometry(file_bytes):
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
| 27 |
rooms = []
|
| 28 |
openings = []
|
| 29 |
floors = 1
|
|
@@ -50,7 +56,7 @@ def extract_geometry(file_bytes):
|
|
| 50 |
y_vals = [p[1] for p in points]
|
| 51 |
length = abs(max(x_vals) - min(x_vals)) / 12 # inches to ft
|
| 52 |
width = abs(max(y_vals) - min(y_vals)) / 12
|
| 53 |
-
height = 10 # default wall height in ft
|
| 54 |
if length > 2 and width > 2: # Room
|
| 55 |
rooms.append((length, width, height))
|
| 56 |
else:
|
|
@@ -93,8 +99,8 @@ def generate_pdf(data_dict):
|
|
| 93 |
return tmp.name
|
| 94 |
|
| 95 |
if uploaded_file:
|
| 96 |
-
file_bytes = uploaded_file.read()
|
| 97 |
-
rooms, wall_thickness, openings, floors = extract_geometry(
|
| 98 |
|
| 99 |
st.success(f"✔️ Parsed {len(rooms)} rooms and {len(openings)} openings across {floors} floor(s).")
|
| 100 |
st.write(f"📏 Wall Thickness: {wall_thickness} ft")
|
|
@@ -106,7 +112,7 @@ if uploaded_file:
|
|
| 106 |
st.write(f"🏖️ **Sand Volume:** {sand:.2f} cft")
|
| 107 |
st.write(f"🪣 **Cement Bags:** {cement} (50kg each)")
|
| 108 |
|
| 109 |
-
#
|
| 110 |
df = pd.DataFrame({
|
| 111 |
"Item": ["Bricks", "Sand (cft)", "Cement (bags)"],
|
| 112 |
"Quantity": [bricks, round(sand, 2), cement]
|
|
@@ -114,7 +120,7 @@ if uploaded_file:
|
|
| 114 |
|
| 115 |
st.dataframe(df)
|
| 116 |
|
| 117 |
-
# Export
|
| 118 |
st.subheader("📤 Export")
|
| 119 |
col1, col2 = st.columns(2)
|
| 120 |
|
|
|
|
| 21 |
|
| 22 |
@st.cache_data
|
| 23 |
def extract_geometry(file_bytes):
|
| 24 |
+
# Wrap file in text buffer and read as ASCII
|
| 25 |
+
try:
|
| 26 |
+
text_buffer = io.TextIOWrapper(file_bytes, encoding='utf-8', errors='ignore')
|
| 27 |
+
doc = ezdxf.read(text_buffer)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
st.error(f"Error reading DXF file: {e}")
|
| 30 |
+
return [], 0.75, [], 1
|
| 31 |
|
| 32 |
+
msp = doc.modelspace()
|
| 33 |
rooms = []
|
| 34 |
openings = []
|
| 35 |
floors = 1
|
|
|
|
| 56 |
y_vals = [p[1] for p in points]
|
| 57 |
length = abs(max(x_vals) - min(x_vals)) / 12 # inches to ft
|
| 58 |
width = abs(max(y_vals) - min(y_vals)) / 12
|
| 59 |
+
height = 10 # default wall height in ft
|
| 60 |
if length > 2 and width > 2: # Room
|
| 61 |
rooms.append((length, width, height))
|
| 62 |
else:
|
|
|
|
| 99 |
return tmp.name
|
| 100 |
|
| 101 |
if uploaded_file:
|
| 102 |
+
file_bytes = io.BytesIO(uploaded_file.read())
|
| 103 |
+
rooms, wall_thickness, openings, floors = extract_geometry(file_bytes)
|
| 104 |
|
| 105 |
st.success(f"✔️ Parsed {len(rooms)} rooms and {len(openings)} openings across {floors} floor(s).")
|
| 106 |
st.write(f"📏 Wall Thickness: {wall_thickness} ft")
|
|
|
|
| 112 |
st.write(f"🏖️ **Sand Volume:** {sand:.2f} cft")
|
| 113 |
st.write(f"🪣 **Cement Bags:** {cement} (50kg each)")
|
| 114 |
|
| 115 |
+
# Table
|
| 116 |
df = pd.DataFrame({
|
| 117 |
"Item": ["Bricks", "Sand (cft)", "Cement (bags)"],
|
| 118 |
"Quantity": [bricks, round(sand, 2), cement]
|
|
|
|
| 120 |
|
| 121 |
st.dataframe(df)
|
| 122 |
|
| 123 |
+
# Export
|
| 124 |
st.subheader("📤 Export")
|
| 125 |
col1, col2 = st.columns(2)
|
| 126 |
|