Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,107 +1,40 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
-
import matplotlib.patches as patches
|
| 4 |
-
import io
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
ax.
|
| 19 |
-
ax.
|
| 20 |
-
ax.
|
| 21 |
-
ax.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
bedroom_width = 15
|
| 26 |
-
bedroom_x = 5
|
| 27 |
-
bedroom_y = 15
|
| 28 |
-
ax.add_patch(patches.Rectangle((bedroom_x, bedroom_y), bedroom_length, bedroom_width, linewidth=2, edgecolor="blue", facecolor="lightblue"))
|
| 29 |
-
ax.text(bedroom_x + bedroom_length/2, bedroom_y + bedroom_width/2, "Bedroom", fontsize=12, ha="center", va="center", color="black")
|
| 30 |
-
|
| 31 |
-
# Room 2 - Living Room
|
| 32 |
-
living_room_length = 25
|
| 33 |
-
living_room_width = 18
|
| 34 |
-
living_room_x = 5
|
| 35 |
-
living_room_y = 0
|
| 36 |
-
ax.add_patch(patches.Rectangle((living_room_x, living_room_y), living_room_length, living_room_width, linewidth=2, edgecolor="green", facecolor="lightgreen"))
|
| 37 |
-
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")
|
| 38 |
-
|
| 39 |
-
# Room 3 - Kitchen
|
| 40 |
-
kitchen_length = 15
|
| 41 |
-
kitchen_width = 10
|
| 42 |
-
kitchen_x = 30
|
| 43 |
-
kitchen_y = 0
|
| 44 |
-
ax.add_patch(patches.Rectangle((kitchen_x, kitchen_y), kitchen_length, kitchen_width, linewidth=2, edgecolor="red", facecolor="lightcoral"))
|
| 45 |
-
ax.text(kitchen_x + kitchen_length/2, kitchen_y + kitchen_width/2, "Kitchen", fontsize=12, ha="center", va="center", color="black")
|
| 46 |
-
|
| 47 |
-
# Room 4 - Bathroom
|
| 48 |
-
bathroom_length = 8
|
| 49 |
-
bathroom_width = 6
|
| 50 |
-
bathroom_x = 30
|
| 51 |
-
bathroom_y = 12
|
| 52 |
-
ax.add_patch(patches.Rectangle((bathroom_x, bathroom_y), bathroom_length, bathroom_width, linewidth=2, edgecolor="purple", facecolor="violet"))
|
| 53 |
-
ax.text(bathroom_x + bathroom_length/2, bathroom_y + bathroom_width/2, "Bathroom", fontsize=12, ha="center", va="center", color="black")
|
| 54 |
-
|
| 55 |
-
# Room 5 - Garage
|
| 56 |
-
garage_length = 20
|
| 57 |
-
garage_width = 15
|
| 58 |
-
garage_x = 5
|
| 59 |
-
garage_y = 35
|
| 60 |
-
ax.add_patch(patches.Rectangle((garage_x, garage_y), garage_length, garage_width, linewidth=2, edgecolor="orange", facecolor="orange"))
|
| 61 |
-
ax.text(garage_x + garage_length/2, garage_y + garage_width/2, "Garage", fontsize=12, ha="center", va="center", color="black")
|
| 62 |
-
|
| 63 |
-
# Adding doors (as small rectangles on the walls)
|
| 64 |
-
ax.add_patch(patches.Rectangle((bedroom_x + 10, bedroom_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Bedroom Door
|
| 65 |
-
ax.add_patch(patches.Rectangle((living_room_x + 10, living_room_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Living Room Door
|
| 66 |
-
ax.add_patch(patches.Rectangle((kitchen_x + 5, kitchen_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Kitchen Door
|
| 67 |
-
ax.add_patch(patches.Rectangle((garage_x + 10, garage_y), 3, 1, linewidth=2, edgecolor="black", facecolor="brown")) # Garage Door
|
| 68 |
-
|
| 69 |
-
# Adding windows (small rectangles on the walls)
|
| 70 |
-
ax.add_patch(patches.Rectangle((bedroom_x + 5, bedroom_y + 15), 5, 1, linewidth=2, edgecolor="blue", facecolor="lightblue")) # Bedroom window
|
| 71 |
-
ax.add_patch(patches.Rectangle((living_room_x + 5, living_room_y + 18), 5, 1, linewidth=2, edgecolor="green", facecolor="lightgreen")) # Living room window
|
| 72 |
-
|
| 73 |
-
# Adding ventilation (small lines representing windows for ventilation)
|
| 74 |
-
ax.plot([living_room_x + 20, living_room_x + 22], [living_room_y + 5, living_room_y + 5], color="black", lw=2) # Ventilation Line
|
| 75 |
-
|
| 76 |
-
# Add title and labels
|
| 77 |
-
ax.set_title(f"House Floor Plan: Length = {length} {unit}, Width = {width} {unit}", fontsize=14)
|
| 78 |
-
ax.set_xlabel(f"Length ({unit})")
|
| 79 |
-
ax.set_ylabel(f"Width ({unit})")
|
| 80 |
-
|
| 81 |
-
# Set limits and remove axes for clarity
|
| 82 |
-
ax.set_xlim(0, length + 10)
|
| 83 |
-
ax.set_ylim(0, width + 10)
|
| 84 |
-
ax.axis('off')
|
| 85 |
-
|
| 86 |
-
return fig
|
| 87 |
-
|
| 88 |
-
# Streamlit interface
|
| 89 |
-
st.title("AutoCAD-style House Layout Drawing")
|
| 90 |
|
| 91 |
-
|
| 92 |
-
length = st.number_input("Enter the Length of the Plot", min_value=1, max_value=1000, value=50)
|
| 93 |
-
width = st.number_input("Enter the Width of the Plot", min_value=1, max_value=1000, value=30)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
unit = st.selectbox("Select Unit", ["ft", "m", "cm"])
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
# Display the plot
|
| 103 |
-
st.pyplot(fig)
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def convert_to_meters(value, unit):
|
| 5 |
+
conversion_factors = {
|
| 6 |
+
"m": 1,
|
| 7 |
+
"ft": 0.3048,
|
| 8 |
+
"cm": 0.01,
|
| 9 |
+
"in": 0.0254
|
| 10 |
+
}
|
| 11 |
+
return value * conversion_factors[unit]
|
| 12 |
+
|
| 13 |
+
def draw_floor_plan(length, width):
|
| 14 |
+
fig, ax = plt.subplots(figsize=(8, 8))
|
| 15 |
+
ax.plot([0, length, length, 0, 0], [0, 0, width, width, 0], marker='o', color='blue')
|
| 16 |
+
ax.set_xlim(-1, length + 1)
|
| 17 |
+
ax.set_ylim(-1, width + 1)
|
| 18 |
+
ax.set_aspect('equal', adjustable='box')
|
| 19 |
+
ax.set_title("Floor Plan")
|
| 20 |
+
ax.set_xlabel("Length (m)")
|
| 21 |
+
ax.set_ylabel("Width (m)")
|
| 22 |
+
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
st.title("Floor Plan Generator")
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
st.write("Enter the dimensions of the floor plan and select the unit of measurement.")
|
|
|
|
| 27 |
|
| 28 |
+
# Input fields
|
| 29 |
+
length = st.number_input("Enter the length:", min_value=0.0, format="%.2f")
|
| 30 |
+
width = st.number_input("Enter the width:", min_value=0.0, format="%.2f")
|
| 31 |
+
unit = st.selectbox("Select the unit:", ["m", "ft", "cm", "in"], index=0)
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
if st.button("Generate Floor Plan"):
|
| 34 |
+
if length > 0 and width > 0:
|
| 35 |
+
length_m = convert_to_meters(length, unit)
|
| 36 |
+
width_m = convert_to_meters(width, unit)
|
| 37 |
+
st.success(f"Dimensions in meters: Length = {length_m:.2f} m, Width = {width_m:.2f} m")
|
| 38 |
+
draw_floor_plan(length_m, width_m)
|
| 39 |
+
else:
|
| 40 |
+
st.error("Please enter positive values for length and width.")
|