ahsangahothi commited on
Commit
23a9e71
·
verified ·
1 Parent(s): ae747e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import matplotlib.pyplot as plt
 
3
 
4
  def convert_to_meters(value, unit):
5
  conversion_factors = {
@@ -10,16 +11,16 @@ def convert_to_meters(value, unit):
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
 
@@ -28,13 +29,27 @@ st.write("Enter the dimensions of the floor plan and select the unit of measurem
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.")
 
1
  import streamlit as st
2
  import matplotlib.pyplot as plt
3
+ import io
4
 
5
  def convert_to_meters(value, unit):
6
  conversion_factors = {
 
11
  }
12
  return value * conversion_factors[unit]
13
 
14
+ def draw_floor_plan(length, width, unit):
15
  fig, ax = plt.subplots(figsize=(8, 8))
16
  ax.plot([0, length, length, 0, 0], [0, 0, width, width, 0], marker='o', color='blue')
17
  ax.set_xlim(-1, length + 1)
18
  ax.set_ylim(-1, width + 1)
19
  ax.set_aspect('equal', adjustable='box')
20
+ ax.set_title(f"Floor Plan ({unit})")
21
+ ax.set_xlabel(f"Length ({unit})")
22
+ ax.set_ylabel(f"Width ({unit})")
23
+ return fig
24
 
25
  st.title("Floor Plan Generator")
26
 
 
29
  # Input fields
30
  length = st.number_input("Enter the length:", min_value=0.0, format="%.2f")
31
  width = st.number_input("Enter the width:", min_value=0.0, format="%.2f")
32
+ unit = st.selectbox("Select the unit:", ["m", "ft", "cm", "in"], index=1)
33
 
34
  if st.button("Generate Floor Plan"):
35
  if length > 0 and width > 0:
36
+ length_converted = convert_to_meters(length, unit) if unit != "m" else length
37
+ width_converted = convert_to_meters(width, unit) if unit != "m" else width
38
+ st.success(f"Dimensions: Length = {length:.2f} {unit}, Width = {width:.2f} {unit}")
39
+ fig = draw_floor_plan(length, width, unit)
40
+
41
+ # Show the plot
42
+ st.pyplot(fig)
43
+
44
+ # Add a download button
45
+ buf = io.BytesIO()
46
+ fig.savefig(buf, format="png")
47
+ buf.seek(0)
48
+ st.download_button(
49
+ label="Download Floor Plan",
50
+ data=buf,
51
+ file_name="floor_plan.png",
52
+ mime="image/png"
53
+ )
54
  else:
55
  st.error("Please enter positive values for length and width.")