amasood commited on
Commit
d0e9f1a
·
verified ·
1 Parent(s): 4b6538a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -49
app.py CHANGED
@@ -1,59 +1,57 @@
1
  import streamlit as st
2
- import random
3
- from PIL import Image, ImageDraw
4
 
5
- def generate_floor_plan(plot_length, plot_width, num_bedrooms, num_bathrooms, num_drawing_rooms, num_dining_rooms, num_kitchens, num_porch, num_store, num_entrance):
6
- # Create a blank floor plan image
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
- # Placeholder: Divide the plot into simple rectangles for each room
12
- rooms = {
13
- 'Bedroom': num_bedrooms,
14
- 'Bathroom': num_bathrooms,
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 = image_width // 4, image_height // 4
25
- for room_type, count in rooms.items():
26
- for _ in range(count):
27
- draw.rectangle([x, y, x + room_width, y + room_height], outline="black", fill=random.choice(["#f0e68c", "#add8e6", "#ffcccb", "#98fb98"]))
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
- return img
35
 
 
36
  st.title("Floor Plan Generator")
37
-
38
- st.sidebar.header("Input Plot Details")
39
- plot_length = st.sidebar.number_input("Length of the plot (in feet):", min_value=10, max_value=100, value=50)
40
- plot_width = st.sidebar.number_input("Width of the plot (in feet):", min_value=10, max_value=100, value=30)
41
-
42
- st.sidebar.header("Input Room Details")
43
- num_bedrooms = st.sidebar.number_input("Number of Bedrooms:", min_value=0, max_value=10, value=2)
44
- num_bathrooms = st.sidebar.number_input("Number of Bathrooms:", min_value=0, max_value=10, value=2)
45
- num_drawing_rooms = st.sidebar.number_input("Number of Drawing Rooms:", min_value=0, max_value=5, value=1)
46
- num_dining_rooms = st.sidebar.number_input("Number of Dining Rooms:", min_value=0, max_value=5, value=1)
47
- num_kitchens = st.sidebar.number_input("Number of Kitchens:", min_value=0, max_value=3, value=1)
48
- num_porch = st.sidebar.number_input("Number of Porches:", min_value=0, max_value=2, value=1)
49
- num_store = st.sidebar.number_input("Number of Stores:", min_value=0, max_value=3, value=1)
50
- num_entrance = st.sidebar.number_input("Number of Entrance Areas:", min_value=0, max_value=2, value=1)
51
-
52
- if st.button("Generate Floor Plan"):
53
- st.write("### Generated Floor Plan")
54
- floor_plan_image = generate_floor_plan(
55
- plot_length, plot_width, num_bedrooms, num_bathrooms,
56
- num_drawing_rooms, num_dining_rooms, num_kitchens,
57
- num_porch, num_store, num_entrance
58
- )
59
- st.image(floor_plan_image, caption="Floor Plan", use_column_width=True)
 
 
 
 
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)