convert 2d floor plan to 3d plan similar to this type "https://cdn.prod.website-files.com/5dcf94bbedfe6a4a06634ead/6056fdf874af23462f85906c_3DStandard-After.jpg"
To upload files, please first save the app
import streamlit as st
import numpy as np
import plotly.graph_objects as go
st.title("2D to 3D Floor Plan Converter")
st.write("Upload a 2D floor plan image to create a basic 3D visualization.")
# File uploader for the 2D floor plan
uploaded_file = st.file_uploader("Choose a floor plan image", type=['png', 'jpg', 'jpeg'])
# Sample 3D visualization (since we can't actually process images in this demo)
def create_sample_3d_plan():
# Create sample room coordinates
walls = [
# Living Room
[0, 0, 0], [5, 0, 0], [5, 4, 0], [0, 4, 0], [0, 0, 0], # Bottom
[0, 0, 3], [5, 0, 3], [5, 4, 3], [0, 4, 3], [0, 0, 3], # Top
]
# Convert to numpy array
walls = np.array(walls)
# Create 3D visualization
fig = go.Figure()
# Add walls
fig.add_trace(go.Scatter3d(
x=walls[:, 0],
y=walls[:, 1],
z=walls[:, 2],
mode='lines',
line=dict(color='blue', width=2),
name='Walls'
))
# Add vertical lines at corners
for i in range(4):
fig.add_trace(go.Scatter3d(
x=[walls[i][0], walls[i+5][0]],
y=[walls[i][1], walls[i+5][1]],
z=[walls[i][2], walls[i+5][2]],
mode='lines',
line=dict(color='blue', width=2),
showlegend=False
))
# Update layout
fig.update_layout(
scene=dict(
aspectmode='data',
camera=dict(
eye=dict(x=1.5, y=1.5, z=1.5)
)
),
showlegend=False,
title="3D Floor Plan Visualization"
)
return fig
# Display sample or create visualization
if uploaded_file is None:
st.info("Please upload a 2D floor plan image. For now, showing a sample 3D visualization.")
fig = create_sample_3d_plan()
st.plotly_chart(fig, use_container_width=True)
else:
st.image(uploaded_file, caption="Uploaded 2D Floor Plan")
st.info("Converting to 3D visualization...")
fig = create_sample_3d_plan()
st.plotly_chart(fig, use_container_width=True)
st.markdown("""
### How it works
1. Upload your 2D floor plan image
2. The app creates a basic 3D visualization with walls and room structure
3. You can rotate and interact with the 3D model using your mouse
### Notes
- This is a simplified demo that shows a basic 3D structure
- In a full implementation, image processing would be used to:
- Detect walls and room boundaries
- Identify doors and windows
- Calculate proper dimensions
- Add textures and materials
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?