ahsangahothi commited on
Commit
2478522
·
verified ·
1 Parent(s): d3f3670

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -2,7 +2,6 @@ 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):
@@ -11,27 +10,25 @@ def fig_to_bytes(fig):
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
@@ -39,7 +36,7 @@ def draw_house(length, width, unit):
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
@@ -47,7 +44,7 @@ def draw_house(length, width, unit):
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
@@ -55,7 +52,7 @@ def draw_house(length, width, unit):
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
@@ -63,17 +60,17 @@ def draw_house(length, width, unit):
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
 
2
  import matplotlib.pyplot as plt
3
  import matplotlib.patches as patches
4
  import io
 
5
 
6
  # Function to convert the figure to bytes for download
7
  def fig_to_bytes(fig):
 
10
  img_bytes.seek(0)
11
  return img_bytes.read()
12
 
13
+ # Function to draw the house floor plan with precise room dimensions and fixed placement
14
  def draw_house(length, width, unit):
15
+ fig, ax = plt.subplots(figsize=(12, 12))
16
+
17
  # Plot the boundary of the house (Plot limits)
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
+ # Room 1 - Bedroom
 
 
24
  bedroom_length = 20
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
 
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
 
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
 
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
 
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