File size: 2,198 Bytes
75cd7d1
 
 
006dc33
75cd7d1
 
006dc33
75cd7d1
 
 
 
 
 
 
 
 
006dc33
 
 
75cd7d1
006dc33
75cd7d1
006dc33
 
 
 
75cd7d1
006dc33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
from openai import OpenAI

# Initialize OpenAI client using Hugging Face secrets
client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])

# Sample architectural prompt
sample_prompt = (
    "A highly detailed, realistic architectural floor plan for a modern tiny home. "
    "The design features an open-concept layout with a multi-functional living space "
    "that combines a compact living area, dining space, and efficient kitchen with smart storage. "
    "A cozy loft bedroom is accessible via a sleek staircase or ladder. The minimalist bathroom "
    "includes a shower. Emphasize large windows with natural light, clean lines, and neutral tones "
    "with subtle accents. Annotate key dimensions and furniture placements. Professional architectural rendering style."
)

# Session state for user prompt
if "prompt" not in st.session_state:
    st.session_state.prompt = ""

st.title("🏠 OpenAI Image Generator: Tiny Home Floor Plan")

# Prompt input area
st.text_area("Enter your prompt:", key="prompt_input", value=st.session_state.prompt, height=200)

# Button to insert sample
if st.button("Insert Sample Prompt"):
    st.session_state.prompt = sample_prompt
    st.rerun()

# Sync prompt state
st.session_state.prompt = st.session_state.prompt_input

# Display the current prompt as read-only
st.text_area("Current prompt being used:", st.session_state.prompt, height=200, disabled=True)

# Generate image
if st.button("Generate Image"):
    if st.session_state.prompt.strip():
        with st.spinner("Generating image..."):
            try:
                response = client.images.generate(
                    model="dall-e-3",
                    prompt=st.session_state.prompt,
                    size="1024x1024",
                    quality="standard",
                    n=1
                )
                image_url = response.data[0].url
                st.image(image_url, caption="Generated Image", use_column_width=True)
                st.markdown(f"[Download Image]({image_url})", unsafe_allow_html=True)
            except Exception as e:
                st.error(f"Error: {e}")
    else:
        st.warning("Please enter a valid prompt.")