Karley8 commited on
Commit
de95d76
·
verified ·
1 Parent(s): 8b629c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -2
app.py CHANGED
@@ -1,14 +1,106 @@
 
 
1
  import streamlit as st
 
2
  from openai import OpenAI
 
 
3
 
4
- # === SETUP ===
5
  st.set_page_config(page_title="AI Architecture Assistant", layout="centered")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
7
 
8
- # === PROMPT SETUP ===
 
9
  if "prompt" not in st.session_state:
10
  st.session_state.prompt = ""
11
 
 
 
12
  sample_prompt = (
13
  "A highly detailed, realistic architectural floor plan for a modern tiny home. "
14
  "The design features an open-concept layout with a multi-functional living space "
@@ -18,6 +110,7 @@ sample_prompt = (
18
  "with subtle accents. Annotate key dimensions and furniture placements. Professional architectural rendering style."
19
  )
20
 
 
21
  # === UI START ===
22
  st.title("🏠 AI Architecture Assistant")
23
  st.caption("Design smarter. Visualize faster. Build better.")
@@ -370,6 +463,47 @@ st.markdown("""
370
  - [Quebec Construction Code](https://www.rbq.gouv.qc.ca/en/technical-buildings/buildings/construction-code.html)
371
  - [Tiny Home Legal Info (Canada)](https://tinyhousecanada.ca/)
372
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
 
374
 
375
 
 
1
+ # === IMPORTS ===
2
+
3
  import streamlit as st
4
+ from PIL import Image
5
  from openai import OpenAI
6
+ from pathlib import Path
7
+
8
 
9
+ # 1. Page Configuration — MUST be first Streamlit command
10
  st.set_page_config(page_title="AI Architecture Assistant", layout="centered")
11
+
12
+
13
+ # ✅ 2. Inline custom CSS with Poppins font and olive green theme
14
+ st.markdown("""
15
+ <style>
16
+ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;700&display=swap');
17
+
18
+ .stApp {
19
+ background-color: #f4f7f5 !important;
20
+ font-family: 'Poppins', sans-serif;
21
+ color: #1e1e1e;
22
+ padding: 1rem;
23
+ }
24
+
25
+ /* Headings */
26
+ h1 {
27
+ font-family: 'Poppins', sans-serif;
28
+ color: #3a5a40 !important;
29
+ font-weight: 700;
30
+ font-size: 2.3rem;
31
+ }
32
+
33
+ h2, h3 {
34
+ font-family: 'Poppins', sans-serif;
35
+ color: #344e41 !important;
36
+ font-weight: 600;
37
+ font-size: 1.4rem;
38
+ }
39
+
40
+ /* Inputs */
41
+ .stTextInput input, .stTextArea textarea {
42
+ background-color: #ffffff !important;
43
+ color: #1e1e1e !important;
44
+ border: 1px solid #c8d6c1;
45
+ border-radius: 10px;
46
+ padding: 14px;
47
+ font-size: 1rem;
48
+ font-family: 'Poppins', sans-serif;
49
+ }
50
+
51
+ /* Buttons */
52
+ .stButton > button {
53
+ background-color: #588157;
54
+ color: white;
55
+ font-weight: 600;
56
+ font-family: 'Poppins', sans-serif;
57
+ padding: 0.7rem 1.6rem;
58
+ font-size: 1rem;
59
+ border: none;
60
+ border-radius: 10px;
61
+ transition: all 0.3s ease;
62
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
63
+ }
64
+
65
+ .stButton > button:hover {
66
+ background-color: #3a5a40;
67
+ box-shadow: 0 4px 10px rgba(0,0,0,0.15);
68
+ }
69
+
70
+ /* Links */
71
+ a {
72
+ color: #3a5a40;
73
+ font-family: 'Poppins', sans-serif;
74
+ text-decoration: none;
75
+ font-weight: 500;
76
+ }
77
+
78
+ a:hover {
79
+ text-decoration: underline;
80
+ color: #2c4030;
81
+ }
82
+ </style>
83
+ """, unsafe_allow_html=True)
84
+
85
+
86
+ # ✅ 3. Logo Display (must come after styling)
87
+ try:
88
+ logo = Image.open("logo.jpg")
89
+ st.image(logo, width=300)
90
+ except FileNotFoundError:
91
+ st.warning("Logo not found. Please ensure 'logo.jpg' is in the same folder as app.py.")
92
+
93
+
94
+ # ✅ 4. Connect to OpenAI
95
  client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
96
 
97
+
98
+ # ✅ 5. Session Setup
99
  if "prompt" not in st.session_state:
100
  st.session_state.prompt = ""
101
 
102
+
103
+ # ✅ 6. Sample Prompt
104
  sample_prompt = (
105
  "A highly detailed, realistic architectural floor plan for a modern tiny home. "
106
  "The design features an open-concept layout with a multi-functional living space "
 
110
  "with subtle accents. Annotate key dimensions and furniture placements. Professional architectural rendering style."
111
  )
112
 
113
+
114
  # === UI START ===
115
  st.title("🏠 AI Architecture Assistant")
116
  st.caption("Design smarter. Visualize faster. Build better.")
 
463
  - [Quebec Construction Code](https://www.rbq.gouv.qc.ca/en/technical-buildings/buildings/construction-code.html)
464
  - [Tiny Home Legal Info (Canada)](https://tinyhousecanada.ca/)
465
  """)
466
+ # === 9. Eco-Friendly Upgrades Agent ===
467
+
468
+ st.markdown("---")
469
+ st.markdown("### 🌱 Suggest Eco-Friendly Upgrades")
470
+
471
+ if st.button("Get Eco-Friendly Suggestions"):
472
+ if st.session_state.prompt.strip():
473
+ with st.spinner("Analyzing your layout for green upgrades..."):
474
+
475
+ def suggest_eco_upgrades(prompt):
476
+ system_instruction = (
477
+ "You are a sustainability expert in residential architecture. "
478
+ "Based on the following home design prompt, suggest 5 to 7 eco-friendly upgrades. "
479
+ "Be specific and include options like energy efficiency, water conservation, material choices, and renewable energy use. "
480
+ "Avoid general advice—tailor suggestions to the design and layout described."
481
+ )
482
+
483
+ response = client.chat.completions.create(
484
+ model="gpt-4",
485
+ messages=[
486
+ {"role": "system", "content": system_instruction},
487
+ {"role": "user", "content": prompt}
488
+ ],
489
+ temperature=0.7
490
+ )
491
+
492
+ return response.choices[0].message.content.strip()
493
+
494
+ eco_suggestions = suggest_eco_upgrades(st.session_state.prompt)
495
+
496
+ st.markdown("### ✅ Recommended Eco-Friendly Features")
497
+ st.markdown(eco_suggestions)
498
+
499
+ # Save to session for summary
500
+ st.session_state.eco_suggestions = eco_suggestions
501
+
502
+ else:
503
+ st.warning("Please enter a prompt first.")
504
+
505
+
506
+
507
 
508
 
509