create interior room decor that adds furniture and furnishes room by taking a empty room image
To upload files, please first save the app
import streamlit as st
from PIL import Image
import numpy as np
import io
st.title("Interior Room Decorator")
st.write("Upload an empty room image and add furniture to decorate it!")
# Upload empty room image
uploaded_file = st.file_uploader("Upload an empty room image", type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
# Display original image
image = Image.open(uploaded_file)
st.image(image, caption='Original Room', use_column_width=True)
# Create two columns for furniture selection and preview
col1, col2 = st.columns(2)
with col1:
st.subheader("Add Furniture")
# Furniture options
furniture_type = st.selectbox(
"Select furniture type",
["Sofa", "Chair", "Table", "Bed", "Lamp", "Bookshelf"]
)
# Furniture color
furniture_color = st.color_picker("Choose furniture color", "#000000")
# Position sliders
st.subheader("Position")
pos_x = st.slider("X position", 0, image.size[0], image.size[0]//2)
pos_y = st.slider("Y position", 0, image.size[1], image.size[1]//2)
# Size sliders
st.subheader("Size")
width = st.slider("Width", 10, 300, 100)
height = st.slider("Height", 10, 300, 100)
with col2:
st.subheader("Preview")
# Create a copy of the original image
decorated_image = image.copy()
# Draw simple furniture shapes
import numpy as np
from PIL import ImageDraw
draw = ImageDraw.Draw(decorated_image)
# Draw different shapes based on furniture type
if furniture_type == "Sofa":
draw.rectangle(
[(pos_x, pos_y), (pos_x + width, pos_y + height)],
fill=furniture_color
)
elif furniture_type == "Chair":
draw.rectangle(
[(pos_x, pos_y), (pos_x + width//2, pos_y + height//2)],
fill=furniture_color
)
elif furniture_type == "Table":
draw.ellipse(
[(pos_x, pos_y), (pos_x + width, pos_y + height)],
fill=furniture_color
)
elif furniture_type == "Bed":
draw.rectangle(
[(pos_x, pos_y), (pos_x + width*1.5, pos_y + height)],
fill=furniture_color
)
elif furniture_type == "Lamp":
# Draw lamp stand
draw.rectangle(
[(pos_x + width//2 - 5, pos_y), (pos_x + width//2 + 5, pos_y + height)],
fill=furniture_color
)
# Draw lamp shade
draw.ellipse(
[(pos_x, pos_y), (pos_x + width, pos_y + height//3)],
fill=furniture_color
)
elif furniture_type == "Bookshelf":
# Draw basic bookshelf
draw.rectangle(
[(pos_x, pos_y), (pos_x + width, pos_y + height)],
fill=furniture_color
)
# Draw shelves
for i in range(4):
draw.line(
[(pos_x, pos_y + (height//4)*i), (pos_x + width, pos_y + (height//4)*i)],
fill='white',
width=2
)
# Display the decorated image
st.image(decorated_image, caption='Decorated Room', use_column_width=True)
# Add download button for the decorated image
buf = io.BytesIO()
decorated_image.save(buf, format='PNG')
st.download_button(
label="Download decorated room",
data=buf.getvalue(),
file_name="decorated_room.png",
mime="image/png"
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?