Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,115 +1,110 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
|
|
|
| 3 |
import io
|
| 4 |
import random
|
| 5 |
|
| 6 |
-
#
|
| 7 |
def fig_to_bytes(fig):
|
| 8 |
img_bytes = io.BytesIO()
|
| 9 |
fig.savefig(img_bytes, format="png")
|
| 10 |
img_bytes.seek(0)
|
| 11 |
return img_bytes.read()
|
| 12 |
|
| 13 |
-
# Function to draw the house floor plan with detailed
|
| 14 |
def draw_house(length, width, unit):
|
| 15 |
-
fig, ax = plt.subplots(figsize=(
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
ax.plot([0, length], [0, 0], color="black", lw=2) # Bottom side
|
| 19 |
ax.plot([0, length], [width, width], color="black", lw=2) # Top side
|
| 20 |
ax.plot([0, 0], [0, width], color="black", lw=2) # Left side
|
| 21 |
ax.plot([length, length], [0, width], color="black", lw=2) # Right side
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
ax.
|
| 31 |
-
ax.
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
ax.
|
| 55 |
-
ax.text(
|
| 56 |
-
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
ax.
|
| 63 |
-
ax.
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
ax.
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
ax.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
ax.plot([
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
x6 = random.randint(0, length//4)
|
| 81 |
-
y6 = random.randint(0, width//4)
|
| 82 |
-
room_length6 = random.randint(6, 10)
|
| 83 |
-
room_width6 = random.randint(4, 8)
|
| 84 |
-
ax.plot([x6, x6 + room_length6], [y6, y6], color="brown", lw=2)
|
| 85 |
-
ax.plot([x6 + room_length6, x6 + room_length6], [y6, y6 - room_width6], color="brown", lw=2)
|
| 86 |
-
ax.plot([x6 + room_length6, x6], [y6 - room_width6, y6 - room_width6], color="brown", lw=2)
|
| 87 |
-
ax.plot([x6, x6], [y6, y6 - room_width6], color="brown", lw=2)
|
| 88 |
-
ax.text(x6 + room_length6//2, y6 - room_width6//2, "Servant Room", fontsize=10, ha="center", color="brown")
|
| 89 |
-
|
| 90 |
-
# Ventilation (Randomly placed)
|
| 91 |
-
x7 = random.randint(length//2, length)
|
| 92 |
-
y7 = random.randint(width//2, width)
|
| 93 |
-
ax.plot([x7, x7 + 4], [y7, y7], color="grey", lw=2)
|
| 94 |
-
ax.text(x7 + 2, y7, "Ventilation", fontsize=8, ha="center", color="grey")
|
| 95 |
-
|
| 96 |
-
# Adding Labels and Title
|
| 97 |
-
ax.set_title(f"Random House Layout: Length = {length} {unit}, Width = {width} {unit}")
|
| 98 |
ax.set_xlabel(f"Length ({unit})")
|
| 99 |
ax.set_ylabel(f"Width ({unit})")
|
| 100 |
|
| 101 |
-
# Set
|
| 102 |
ax.set_xlim(0, length + 10)
|
| 103 |
ax.set_ylim(0, width + 10)
|
| 104 |
-
|
| 105 |
-
# Hide the axes for better visual
|
| 106 |
ax.axis('off')
|
| 107 |
|
| 108 |
return fig
|
| 109 |
|
| 110 |
# Streamlit interface
|
| 111 |
-
st.title("
|
| 112 |
|
| 113 |
# User input for plot dimensions and units
|
| 114 |
length = st.number_input("Enter the Length of the Plot", min_value=1, max_value=1000, value=50)
|
| 115 |
-
width = st.number_input("Enter the Width of
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
+
import matplotlib.patches as patches
|
| 4 |
import io
|
| 5 |
import random
|
| 6 |
|
| 7 |
+
# Function to convert the figure to bytes for download
|
| 8 |
def fig_to_bytes(fig):
|
| 9 |
img_bytes = io.BytesIO()
|
| 10 |
fig.savefig(img_bytes, format="png")
|
| 11 |
img_bytes.seek(0)
|
| 12 |
return img_bytes.read()
|
| 13 |
|
| 14 |
+
# Function to draw the house floor plan with detailed rooms, windows, doors, and walls
|
| 15 |
def draw_house(length, width, unit):
|
| 16 |
+
fig, ax = plt.subplots(figsize=(10, 10))
|
| 17 |
+
|
| 18 |
+
# Plot the boundary of the house (Plot limits)
|
| 19 |
ax.plot([0, length], [0, 0], color="black", lw=2) # Bottom side
|
| 20 |
ax.plot([0, length], [width, width], color="black", lw=2) # Top side
|
| 21 |
ax.plot([0, 0], [0, width], color="black", lw=2) # Left side
|
| 22 |
ax.plot([length, length], [0, width], color="black", lw=2) # Right side
|
| 23 |
|
| 24 |
+
# Define Room Dimensions and Placement (For this example we place 5 rooms)
|
| 25 |
+
|
| 26 |
+
# Bedroom (Fixed position for simplicity, real app should randomize it)
|
| 27 |
+
bedroom_length = 20
|
| 28 |
+
bedroom_width = 15
|
| 29 |
+
bedroom_x = 5
|
| 30 |
+
bedroom_y = 15
|
| 31 |
+
ax.add_patch(patches.Rectangle((bedroom_x, bedroom_y), bedroom_length, bedroom_width, linewidth=2, edgecolor="blue", facecolor="lightblue"))
|
| 32 |
+
ax.text(bedroom_x + bedroom_length/2, bedroom_y + bedroom_width/2, "Bedroom", fontsize=12, ha="center", va="center", color="black")
|
| 33 |
+
|
| 34 |
+
# Living Room
|
| 35 |
+
living_room_length = 25
|
| 36 |
+
living_room_width = 18
|
| 37 |
+
living_room_x = 5
|
| 38 |
+
living_room_y = 0
|
| 39 |
+
ax.add_patch(patches.Rectangle((living_room_x, living_room_y), living_room_length, living_room_width, linewidth=2, edgecolor="green", facecolor="lightgreen"))
|
| 40 |
+
ax.text(living_room_x + living_room_length/2, living_room_y + living_room_width/2, "Living Room", fontsize=12, ha="center", va="center", color="black")
|
| 41 |
+
|
| 42 |
+
# Kitchen
|
| 43 |
+
kitchen_length = 15
|
| 44 |
+
kitchen_width = 10
|
| 45 |
+
kitchen_x = 30
|
| 46 |
+
kitchen_y = 0
|
| 47 |
+
ax.add_patch(patches.Rectangle((kitchen_x, kitchen_y), kitchen_length, kitchen_width, linewidth=2, edgecolor="red", facecolor="lightcoral"))
|
| 48 |
+
ax.text(kitchen_x + kitchen_length/2, kitchen_y + kitchen_width/2, "Kitchen", fontsize=12, ha="center", va="center", color="black")
|
| 49 |
+
|
| 50 |
+
# Bathroom
|
| 51 |
+
bathroom_length = 8
|
| 52 |
+
bathroom_width = 6
|
| 53 |
+
bathroom_x = 30
|
| 54 |
+
bathroom_y = 12
|
| 55 |
+
ax.add_patch(patches.Rectangle((bathroom_x, bathroom_y), bathroom_length, bathroom_width, linewidth=2, edgecolor="purple", facecolor="violet"))
|
| 56 |
+
ax.text(bathroom_x + bathroom_length/2, bathroom_y + bathroom_width/2, "Bathroom", fontsize=12, ha="center", va="center", color="black")
|
| 57 |
+
|
| 58 |
+
# Garage
|
| 59 |
+
garage_length = 20
|
| 60 |
+
garage_width = 15
|
| 61 |
+
garage_x = 5
|
| 62 |
+
garage_y = 35
|
| 63 |
+
ax.add_patch(patches.Rectangle((garage_x, garage_y), garage_length, garage_width, linewidth=2, edgecolor="orange", facecolor="orange"))
|
| 64 |
+
ax.text(garage_x + garage_length/2, garage_y + garage_width/2, "Garage", fontsize=12, ha="center", va="center", color="black")
|
| 65 |
+
|
| 66 |
+
# Drawing some doors as small rectangles
|
| 67 |
+
ax.add_patch(patches.Rectangle((bedroom_x + 10, bedroom_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Bedroom Door
|
| 68 |
+
ax.add_patch(patches.Rectangle((living_room_x + 10, living_room_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Living Room Door
|
| 69 |
+
ax.add_patch(patches.Rectangle((kitchen_x + 5, kitchen_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Kitchen Door
|
| 70 |
+
ax.add_patch(patches.Rectangle((garage_x + 10, garage_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Garage Door
|
| 71 |
+
|
| 72 |
+
# Adding window details (small rectangles representing windows)
|
| 73 |
+
ax.add_patch(patches.Rectangle((bedroom_x + 5, bedroom_y + 15), 5, 1, linewidth=2, edgecolor="blue", facecolor="lightblue")) # Bedroom window
|
| 74 |
+
ax.add_patch(patches.Rectangle((living_room_x + 5, living_room_y + 18), 5, 1, linewidth=2, edgecolor="green", facecolor="lightgreen")) # Living room window
|
| 75 |
+
|
| 76 |
+
# Adding Ventilation (Small lines for windows)
|
| 77 |
+
ax.plot([living_room_x + 20, living_room_x + 22], [living_room_y + 5, living_room_y + 5], color="black", lw=2) # Ventilation Line
|
| 78 |
+
|
| 79 |
+
# Add title and labels
|
| 80 |
+
ax.set_title(f"House Floor Plan: Length = {length} {unit}, Width = {width} {unit}", fontsize=14)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
ax.set_xlabel(f"Length ({unit})")
|
| 82 |
ax.set_ylabel(f"Width ({unit})")
|
| 83 |
|
| 84 |
+
# Set limits and remove axes for clarity
|
| 85 |
ax.set_xlim(0, length + 10)
|
| 86 |
ax.set_ylim(0, width + 10)
|
|
|
|
|
|
|
| 87 |
ax.axis('off')
|
| 88 |
|
| 89 |
return fig
|
| 90 |
|
| 91 |
# Streamlit interface
|
| 92 |
+
st.title("AutoCAD-style House Layout Drawing")
|
| 93 |
|
| 94 |
# User input for plot dimensions and units
|
| 95 |
length = st.number_input("Enter the Length of the Plot", min_value=1, max_value=1000, value=50)
|
| 96 |
+
width = st.number_input("Enter the Width of the Plot", min_value=1, max_value=1000, value=30)
|
| 97 |
+
|
| 98 |
+
# Dropdown menu for unit selection
|
| 99 |
+
unit = st.selectbox("Select Unit", ["ft", "m", "cm"])
|
| 100 |
+
|
| 101 |
+
# Draw the house layout when inputs are provided
|
| 102 |
+
if length and width:
|
| 103 |
+
fig = draw_house(length, width, unit)
|
| 104 |
+
|
| 105 |
+
# Display the plot
|
| 106 |
+
st.pyplot(fig)
|
| 107 |
+
|
| 108 |
+
# Option to download the floor plan as a PNG image
|
| 109 |
+
img_data = fig_to_bytes(fig)
|
| 110 |
+
st.download_button("Download Floor Plan", img_data, file_name="house_layout.png", mime="image/png")
|