floor_plan / app.py
amasood's picture
Update app.py
d0e9f1a verified
import streamlit as st
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def generate_floor_plan(plot_length, plot_width, rooms):
fig, ax = plt.subplots(figsize=(10, 8))
# Plot dimensions
ax.set_xlim(0, plot_length)
ax.set_ylim(0, plot_width)
ax.set_aspect("equal")
# Draw boundary
ax.add_patch(patches.Rectangle((0, 0), plot_length, plot_width, edgecolor="black", facecolor="none", linewidth=2))
# Layout rooms as simple rectangles
x, y = 0, 0
room_width, room_height = plot_length / 4, plot_width / len(rooms)
for room_name, room_count in rooms.items():
for _ in range(room_count):
if x + room_width > plot_length: # Move to the next row
x = 0
y += room_height
ax.add_patch(patches.Rectangle((x, y), room_width, room_height, edgecolor="blue", facecolor="lightblue", linewidth=1))
ax.text(x + room_width / 2, y + room_height / 2, room_name, ha="center", va="center", fontsize=10)
x += room_width
st.pyplot(fig)
# Streamlit UI
st.title("Floor Plan Generator")
st.sidebar.header("Plot Dimensions")
plot_length = st.sidebar.number_input("Plot Length (in feet)", min_value=10, max_value=200, value=50, step=1)
plot_width = st.sidebar.number_input("Plot Width (in feet)", min_value=10, max_value=200, value=40, step=1)
st.sidebar.header("Rooms Configuration")
bedrooms = st.sidebar.number_input("Number of Bedrooms", min_value=0, max_value=10, value=2, step=1)
bathrooms = st.sidebar.number_input("Number of Bathrooms", min_value=0, max_value=10, value=1, step=1)
drawing_rooms = st.sidebar.number_input("Number of Drawing Rooms", min_value=0, max_value=5, value=1, step=1)
dining_rooms = st.sidebar.number_input("Number of Dining Rooms", min_value=0, max_value=5, value=1, step=1)
kitchens = st.sidebar.number_input("Number of Kitchens", min_value=0, max_value=3, value=1, step=1)
porches = st.sidebar.number_input("Number of Porches", min_value=0, max_value=3, value=1, step=1)
stores = st.sidebar.number_input("Number of Stores", min_value=0, max_value=3, value=1, step=1)
entrance_areas = st.sidebar.number_input("Number of Entrance Areas", min_value=0, max_value=3, value=1, step=1)
if st.sidebar.button("Generate Floor Plan"):
rooms = {
"Bedroom": bedrooms,
"Bathroom": bathrooms,
"Drawing Room": drawing_rooms,
"Dining Room": dining_rooms,
"Kitchen": kitchens,
"Porch": porches,
"Store": stores,
"Entrance Area": entrance_areas,
}
generate_floor_plan(plot_length, plot_width, rooms)