Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,57 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
|
| 5 |
-
def generate_floor_plan(plot_length, plot_width,
|
| 6 |
-
|
| 7 |
-
image_width, image_height = plot_width * 10, plot_length * 10
|
| 8 |
-
img = Image.new('RGB', (image_width, image_height), 'white')
|
| 9 |
-
draw = ImageDraw.Draw(img)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
'Drawing Room': num_drawing_rooms,
|
| 16 |
-
'Dining Room': num_dining_rooms,
|
| 17 |
-
'Kitchen': num_kitchens,
|
| 18 |
-
'Porch': num_porch,
|
| 19 |
-
'Store': num_store,
|
| 20 |
-
'Entrance': num_entrance
|
| 21 |
-
}
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
x, y = 0, 0
|
| 24 |
-
room_width, room_height =
|
| 25 |
-
for
|
| 26 |
-
for _ in range(
|
| 27 |
-
|
| 28 |
-
draw.text((x + 10, y + 10), room_type, fill="black")
|
| 29 |
-
x += room_width
|
| 30 |
-
if x >= image_width:
|
| 31 |
x = 0
|
| 32 |
y += room_height
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
|
|
|
|
| 36 |
st.title("Floor Plan Generator")
|
| 37 |
-
|
| 38 |
-
st.sidebar.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
st.sidebar.
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import matplotlib.patches as patches
|
| 4 |
|
| 5 |
+
def generate_floor_plan(plot_length, plot_width, rooms):
|
| 6 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Plot dimensions
|
| 9 |
+
ax.set_xlim(0, plot_length)
|
| 10 |
+
ax.set_ylim(0, plot_width)
|
| 11 |
+
ax.set_aspect("equal")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Draw boundary
|
| 14 |
+
ax.add_patch(patches.Rectangle((0, 0), plot_length, plot_width, edgecolor="black", facecolor="none", linewidth=2))
|
| 15 |
+
|
| 16 |
+
# Layout rooms as simple rectangles
|
| 17 |
x, y = 0, 0
|
| 18 |
+
room_width, room_height = plot_length / 4, plot_width / len(rooms)
|
| 19 |
+
for room_name, room_count in rooms.items():
|
| 20 |
+
for _ in range(room_count):
|
| 21 |
+
if x + room_width > plot_length: # Move to the next row
|
|
|
|
|
|
|
|
|
|
| 22 |
x = 0
|
| 23 |
y += room_height
|
| 24 |
+
ax.add_patch(patches.Rectangle((x, y), room_width, room_height, edgecolor="blue", facecolor="lightblue", linewidth=1))
|
| 25 |
+
ax.text(x + room_width / 2, y + room_height / 2, room_name, ha="center", va="center", fontsize=10)
|
| 26 |
+
x += room_width
|
| 27 |
|
| 28 |
+
st.pyplot(fig)
|
| 29 |
|
| 30 |
+
# Streamlit UI
|
| 31 |
st.title("Floor Plan Generator")
|
| 32 |
+
st.sidebar.header("Plot Dimensions")
|
| 33 |
+
plot_length = st.sidebar.number_input("Plot Length (in feet)", min_value=10, max_value=200, value=50, step=1)
|
| 34 |
+
plot_width = st.sidebar.number_input("Plot Width (in feet)", min_value=10, max_value=200, value=40, step=1)
|
| 35 |
+
|
| 36 |
+
st.sidebar.header("Rooms Configuration")
|
| 37 |
+
bedrooms = st.sidebar.number_input("Number of Bedrooms", min_value=0, max_value=10, value=2, step=1)
|
| 38 |
+
bathrooms = st.sidebar.number_input("Number of Bathrooms", min_value=0, max_value=10, value=1, step=1)
|
| 39 |
+
drawing_rooms = st.sidebar.number_input("Number of Drawing Rooms", min_value=0, max_value=5, value=1, step=1)
|
| 40 |
+
dining_rooms = st.sidebar.number_input("Number of Dining Rooms", min_value=0, max_value=5, value=1, step=1)
|
| 41 |
+
kitchens = st.sidebar.number_input("Number of Kitchens", min_value=0, max_value=3, value=1, step=1)
|
| 42 |
+
porches = st.sidebar.number_input("Number of Porches", min_value=0, max_value=3, value=1, step=1)
|
| 43 |
+
stores = st.sidebar.number_input("Number of Stores", min_value=0, max_value=3, value=1, step=1)
|
| 44 |
+
entrance_areas = st.sidebar.number_input("Number of Entrance Areas", min_value=0, max_value=3, value=1, step=1)
|
| 45 |
+
|
| 46 |
+
if st.sidebar.button("Generate Floor Plan"):
|
| 47 |
+
rooms = {
|
| 48 |
+
"Bedroom": bedrooms,
|
| 49 |
+
"Bathroom": bathrooms,
|
| 50 |
+
"Drawing Room": drawing_rooms,
|
| 51 |
+
"Dining Room": dining_rooms,
|
| 52 |
+
"Kitchen": kitchens,
|
| 53 |
+
"Porch": porches,
|
| 54 |
+
"Store": stores,
|
| 55 |
+
"Entrance Area": entrance_areas,
|
| 56 |
+
}
|
| 57 |
+
generate_floor_plan(plot_length, plot_width, rooms)
|