File size: 1,746 Bytes
57c842c
 
23a9e71
e4a17a0
a0a9cd6
 
 
 
 
 
 
 
 
23a9e71
5b18fd3
a0a9cd6
c914f9a
 
 
69eeee0
23a9e71
 
 
 
57c842c
a0a9cd6
d3f3670
a0a9cd6
d3f3670
a0a9cd6
 
 
23a9e71
d3f3670
a0a9cd6
 
23a9e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0a9cd6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
import matplotlib.pyplot as plt
import io

def convert_to_meters(value, unit):
    conversion_factors = {
        "m": 1,
        "ft": 0.3048,
        "cm": 0.01,
        "in": 0.0254
    }
    return value * conversion_factors[unit]

def draw_floor_plan(length, width, unit):
    fig, ax = plt.subplots(figsize=(8, 6))
    ax.plot([0, length, length, 0, 0], [0, 0, width, width, 0], marker='o', color='blue')
    ax.set_xlim(0, length * 1.1)
    ax.set_ylim(0, width * 1.1)
    ax.set_aspect('equal')  # Maintain aspect ratio for accurate proportions
    ax.grid(True, linestyle='--', alpha=0.6)
    ax.set_title(f"Floor Plan ({unit})")
    ax.set_xlabel(f"Length ({unit})")
    ax.set_ylabel(f"Width ({unit})")
    return fig

st.title("Floor Plan Generator")

st.write("Enter the dimensions of the floor plan and select the unit of measurement.")

# Input fields
length = st.number_input("Enter the length:", min_value=0.0, format="%.2f")
width = st.number_input("Enter the width:", min_value=0.0, format="%.2f")
unit = st.selectbox("Select the unit:", ["m", "ft", "cm", "in"], index=1)

if st.button("Generate Floor Plan"):
    if length > 0 and width > 0:
        st.success(f"Dimensions: Length = {length:.2f} {unit}, Width = {width:.2f} {unit}")
        fig = draw_floor_plan(length, width, unit)

        # Show the plot
        st.pyplot(fig)

        # Add a download button
        buf = io.BytesIO()
        fig.savefig(buf, format="png")
        buf.seek(0)
        st.download_button(
            label="Download Floor Plan",
            data=buf,
            file_name="floor_plan.png",
            mime="image/png"
        )
    else:
        st.error("Please enter positive values for length and width.")