syedwaqarumer's picture
Update app.py
4a593a2 verified
import streamlit as st
import matplotlib.pyplot as plt
import matplotlib.patches as patches
# Function to generate a floor plan similar to the uploaded image
def generate_stylized_floor_plan(building_length, building_width, rooms):
fig, ax = plt.subplots(figsize=(10, 10))
# Set the boundaries of the building
ax.set_xlim(0, building_length)
ax.set_ylim(0, building_width)
# Configure the plot to match AutoCAD-style map visuals
ax.set_facecolor("white")
# Style options to emulate AutoCAD or blueprint-like appearance
boundary_color = 'black'
boundary_thickness = 3 # Thicker boundary to resemble walls
current_x = 0
current_y = building_width
for room in rooms:
room_width, room_height, room_name = room
# Ensure room fits within the building's length, otherwise move to next row
if current_x + room_width > building_length:
current_x = 0
current_y -= room_height
if current_y - room_height < 0:
st.error("The rooms don't fit within the building dimensions.")
return
# Draw room boundaries (thick lines like walls)
ax.add_patch(patches.Rectangle((current_x, current_y - room_height), room_width, room_height,
edgecolor=boundary_color, facecolor='none', lw=boundary_thickness))
# Label the room with its name and dimensions, centered
room_label = f"{room_name}\n{room_width}' x {room_height}'"
# Apply text label directly, removing fontdict to avoid conflicts
ax.text(current_x + room_width / 2, current_y - room_height / 2, room_label,
ha='center', va='center', fontsize=12, color='black', weight='bold', family='serif')
current_x += room_width
ax.set_aspect('equal')
ax.invert_yaxis() # Invert y-axis for blueprint-style display
ax.set_axis_off() # Hide axes for cleaner appearance
st.pyplot(fig)
# Streamlit app title
st.title("Stylized Building Floor Plan Generator")
# Get input from the user
building_length = st.number_input("Building Length (ft)", value=50)
building_width = st.number_input("Building Width (ft)", value=40)
num_rooms = st.slider("Number of Rooms", 1, 10, 4)
rooms = []
# Input room details
for i in range(num_rooms):
st.subheader(f"Room {i + 1} Details")
room_name = st.text_input(f"Room {i + 1} Name", value=f"Room {i + 1}")
room_width = st.number_input(f"Room {i + 1} Width (ft)", value=10, min_value=1)
room_height = st.number_input(f"Room {i + 1} Height (ft)", value=10, min_value=1)
rooms.append((room_width, room_height, room_name))
# Generate button
if st.button("Generate Floor Plan"):
generate_stylized_floor_plan(building_length, building_width, rooms)