Update app.py
Browse files
app.py
CHANGED
|
@@ -119,6 +119,71 @@ if "requirements_summary" in st.session_state:
|
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
st.error(f"β Replicate API failed: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
|
|
|
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
st.error(f"β Replicate API failed: {e}")
|
| 122 |
+
# === Agent 3: Material Explorer ===
|
| 123 |
+
import re
|
| 124 |
+
|
| 125 |
+
st.header("Agent 3: Material Explorer")
|
| 126 |
+
|
| 127 |
+
# Use the previous layout description as input
|
| 128 |
+
your_dalle_prompt = st.session_state.get("requirements_summary", "")
|
| 129 |
+
|
| 130 |
+
if st.button("Get Suggested Materials"):
|
| 131 |
+
with st.spinner("Using Gemini to extract materials..."):
|
| 132 |
+
|
| 133 |
+
material_prompt = f"""
|
| 134 |
+
From the following blueprint prompt and layout concept:
|
| 135 |
+
|
| 136 |
+
Blueprint Prompt:
|
| 137 |
+
\"\"\"{your_dalle_prompt}\"\"\"
|
| 138 |
+
|
| 139 |
+
Return 5 key building materials implied by the layout, even if not explicitly listed.
|
| 140 |
+
|
| 141 |
+
Respond ONLY with a raw JSON list like:
|
| 142 |
+
["Concrete slab foundation", "Metal roofing", "Plywood sheathing", "Double-pane windows", "Insulation"]
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
model = genai.GenerativeModel("gemini-1.5-pro")
|
| 147 |
+
response = model.generate_content(material_prompt)
|
| 148 |
+
raw = response.text.strip()
|
| 149 |
+
cleaned = re.sub(r"```json|```", "", raw).strip()
|
| 150 |
+
materials = json.loads(cleaned)
|
| 151 |
+
st.session_state.materials = materials
|
| 152 |
+
st.success("β
Materials extracted from layout!")
|
| 153 |
+
except Exception as e:
|
| 154 |
+
st.error("β Could not parse Gemini response.")
|
| 155 |
+
st.code(raw)
|
| 156 |
+
materials = []
|
| 157 |
+
|
| 158 |
+
# Predefined Home Depot product links
|
| 159 |
+
material_links = {
|
| 160 |
+
"Engineered wood flooring": "https://www.homedepot.ca/product/home-decorators-collection-laminate-flooring-castle-oak/1001624267",
|
| 161 |
+
"Laminate countertops": "https://www.homedepot.ca/product/hampton-bay-premium-laminate-countertop-butchers-block/1001185104",
|
| 162 |
+
"Tile (bathroom)": "https://www.homedepot.ca/product/enigma-12-inch-x-24-inch-glazed-porcelain-tile-aria-grey/1001066513",
|
| 163 |
+
"Painted drywall": "https://www.homedepot.ca/product/certainteed-1-2-inch-x-4-ft-x-8-ft-drywall/1000116648",
|
| 164 |
+
"Wood framing (stud walls)": "https://www.homedepot.ca/product/2-inch-x-4-inch-x-8-ft-construction-grade-lumber/1000115194",
|
| 165 |
+
"Spray foam insulation": "https://www.homedepot.ca/product/great-stuff-big-gap-filler-insulating-foam-sealant-12-oz/1000110899",
|
| 166 |
+
"Triple-glazed windows": "https://www.homedepot.ca/product/american-craftsman-60-inch-x-60-inch-double-pane-double-hung-vinyl-window/1001202871",
|
| 167 |
+
"Metal roofing": "https://www.homedepot.ca/product/ondura-36-inch-x-79-inch-black-roof-panel/1000167679",
|
| 168 |
+
"Solar panel kit": "https://www.homedepot.ca/product/nature-power-110-watt-solar-panel-kit-with-inverter-and-charging-controller/1001037002",
|
| 169 |
+
"Mini wood stove": "https://www.homedepot.ca/product/englander-1-200-sq-ft-wood-burning-stove/1000829230"
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
# Show links in Streamlit
|
| 173 |
+
if "materials" in st.session_state:
|
| 174 |
+
st.subheader("π Explore Suggested Materials")
|
| 175 |
+
|
| 176 |
+
cols = st.columns(2)
|
| 177 |
+
|
| 178 |
+
for i, mat in enumerate(st.session_state.materials):
|
| 179 |
+
col = cols[i % 2]
|
| 180 |
+
with col:
|
| 181 |
+
url = material_links.get(mat)
|
| 182 |
+
if url:
|
| 183 |
+
st.markdown(f"β
**{mat}**\n\n[π View Product on Home Depot]({url})", unsafe_allow_html=True)
|
| 184 |
+
else:
|
| 185 |
+
st.markdown(f"π‘ **{mat}**\n\n_(no direct link available)_")
|
| 186 |
+
|
| 187 |
|
| 188 |
|
| 189 |
|