convert only floor plan Sketch to CAD-Style Floor Plan
Drop files here
or click to upload
import streamlit as st
from PIL import Image
import io
import os
from dotenv import load_dotenv
import openai
st.set_page_config(page_title="Floor Plan Sketch to CAD Converter", layout="wide")
st.title("Floor Plan Sketch to CAD-Style Converter")
st.write("""
Upload a hand-drawn floor plan sketch and convert it to a CAD-style floor plan using AI.
Please note that you'll need to provide your own OpenAI API key.
""")
# File uploader
uploaded_file = st.file_uploader("Upload your floor plan sketch (PNG, JPG, JPEG)", type=['png', 'jpg', 'jpeg'])
# API Key input
api_key = st.text_input("Enter your OpenAI API key", type="password")
if uploaded_file and api_key:
try:
# Display the uploaded image
st.subheader("Uploaded Sketch")
image = Image.open(uploaded_file)
st.image(image, use_column_width=True)
if st.button("Convert to CAD-Style"):
with st.spinner("Converting your sketch... This may take a few moments."):
# Initialize OpenAI client
client = openai.OpenAI(api_key=api_key)
# Prepare the image for the API
bytes_data = io.BytesIO()
image.save(bytes_data, format=image.format)
bytes_data = bytes_data.getvalue()
try:
response = client.images.edit(
image=bytes_data,
prompt="Convert this floor plan sketch to a precise, professional CAD-style architectural drawing with clean lines, proper dimensions, and standard architectural symbols. Use black lines on white background.",
n=1,
size="1024x1024"
)
# Display the result
st.subheader("Converted CAD-Style Floor Plan")
st.image(response.data[0].url, use_column_width=True)
# Add download button for the converted image
st.markdown(f"[Download Converted Image]({response.data[0].url})")
except Exception as e:
st.error(f"Error during conversion: {str(e)}")
except Exception as e:
st.error(f"Error processing the image: {str(e)}")
st.markdown("""
### Instructions:
1. Upload a clear photo or scan of your hand-drawn floor plan sketch
2. Enter your OpenAI API key
3. Click 'Convert to CAD-Style' to generate the conversion
4. Download the converted image if desired
### Tips for best results:
- Use clear, dark lines in your sketch
- Ensure good lighting and contrast in your photo/scan
- Avoid including unnecessary details or text
- Keep the sketch oriented correctly (north up)
""")
# Footer
st.markdown("---")
st.markdown("Built with Streamlit and OpenAI API")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?