2d to 3d floor plan converter with 3d visualization that gives labels similar to 2d plan and only takes 2d floor plans no other images
To upload files, please first save the app
import streamlit as st
import numpy as np
import plotly.graph_objects as go
from PIL import Image
import io
import matplotlib.pyplot as plt
st.title("2D to 3D Floor Plan Converter")
# File uploader for 2D floor plan
uploaded_file = st.file_uploader("Upload your 2D floor plan (PNG, JPG)", type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
# Read and display the original image
image = Image.open(uploaded_file)
st.image(image, caption='Original 2D Floor Plan', use_column_width=True)
# Convert image to numpy array and get dimensions
img_array = np.array(image)
height, width = img_array.shape[:2]
# Create a simple 3D representation
# We'll create a basic extrusion of the floor plan
# Create floor coordinates
x = np.linspace(0, width, width)
y = np.linspace(0, height, height)
X, Y = np.meshgrid(x, y)
Z = np.zeros_like(X) # Base floor level
# Create walls (simplified representation)
wall_height = 100 # Arbitrary wall height
# Create the 3D visualization using Plotly
fig = go.Figure()
# Add floor
fig.add_trace(go.Surface(
x=X,
y=Y,
z=Z,
colorscale='Greys',
showscale=False,
opacity=0.8,
name='Floor'
))
# Add walls (simplified representation)
# We'll create vertical surfaces at the edges
for i in range(0, width, width//10):
wall_x = [i, i, i, i]
wall_y = [0, height, height, 0]
wall_z = [0, 0, wall_height, wall_height]
fig.add_trace(go.Mesh3d(
x=wall_x,
y=wall_y,
z=wall_z,
color='lightgrey',
opacity=0.6,
name='Wall'
))
# Add some sample room labels
rooms = {
'Living Room': [width/4, height/4, wall_height/2],
'Kitchen': [3*width/4, height/4, wall_height/2],
'Bedroom': [width/2, 3*height/4, wall_height/2],
}
# Add room labels
for room, pos in rooms.items():
fig.add_trace(go.Scatter3d(
x=[pos[0]],
y=[pos[1]],
z=[pos[2]],
mode='text',
text=[room],
textposition='middle center',
textfont=dict(size=12),
name=room
))
# Update layout
fig.update_layout(
title='3D Floor Plan Visualization',
scene=dict(
xaxis_title='Width',
yaxis_title='Length',
zaxis_title='Height',
camera=dict(
eye=dict(x=1.5, y=1.5, z=1.5)
)
),
showlegend=False,
width=800,
height=800
)
# Display the 3D visualization
st.plotly_chart(fig)
st.info("""
Note: This is a simplified 3D representation of your floor plan. The conversion:
- Creates a basic floor surface
- Adds simplified walls
- Includes sample room labels
- Allows for interactive 3D viewing (you can rotate, zoom, and pan)
For more accurate results, consider using specialized architectural software.
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?