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.")