Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -270,9 +270,9 @@ with tab3:
|
|
270 |
st.session_state.tech_thread_id = None
|
271 |
if "tech_results" not in st.session_state:
|
272 |
st.session_state.tech_results = []
|
273 |
-
st.session_state
|
|
|
274 |
|
275 |
-
# β
Input moved inside tab3 block
|
276 |
tech_input = st.chat_input("Ask about plans, drawings or components")
|
277 |
if tech_input:
|
278 |
st.session_state.tech_messages.append({"role": "user", "content": tech_input})
|
@@ -308,25 +308,28 @@ with tab3:
|
|
308 |
messages = client.beta.threads.messages.list(thread_id=st.session_state.tech_thread_id)
|
309 |
for msg in reversed(messages.data):
|
310 |
if msg.role == "assistant":
|
311 |
-
|
312 |
-
st.session_state.tech_messages.append({"role": "assistant", "content": content})
|
313 |
try:
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
317 |
break
|
318 |
except Exception as e:
|
319 |
st.error(f"β Technical Assistant Error: {e}")
|
320 |
|
321 |
with st.expander("π§ Options (Filter + Pagination)", expanded=False):
|
322 |
disciplines = sorted(set(d.get("discipline", "") for d in st.session_state.tech_results))
|
323 |
-
|
324 |
page_size = 8
|
325 |
page = st.number_input("Page", min_value=1, step=1, value=1)
|
326 |
|
327 |
if st.session_state.tech_results:
|
328 |
st.subheader("π Results")
|
329 |
-
results = [r for r in st.session_state.tech_results if
|
330 |
paged = results[(page - 1) * page_size : page * page_size]
|
331 |
cols = st.columns(4)
|
332 |
for i, item in enumerate(paged):
|
@@ -338,22 +341,36 @@ with tab3:
|
|
338 |
if not image_urls:
|
339 |
st.warning("β οΈ No image available.")
|
340 |
else:
|
341 |
-
url
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
st.
|
|
|
353 |
if st.button("β Close Preview"):
|
354 |
st.session_state.tech_lightbox = None
|
355 |
st.rerun()
|
356 |
else:
|
357 |
-
|
358 |
-
|
359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
st.session_state.tech_thread_id = None
|
271 |
if "tech_results" not in st.session_state:
|
272 |
st.session_state.tech_results = []
|
273 |
+
if "tech_lightbox" not in st.session_state:
|
274 |
+
st.session_state.tech_lightbox = None
|
275 |
|
|
|
276 |
tech_input = st.chat_input("Ask about plans, drawings or components")
|
277 |
if tech_input:
|
278 |
st.session_state.tech_messages.append({"role": "user", "content": tech_input})
|
|
|
308 |
messages = client.beta.threads.messages.list(thread_id=st.session_state.tech_thread_id)
|
309 |
for msg in reversed(messages.data):
|
310 |
if msg.role == "assistant":
|
311 |
+
raw = msg.content[0].text.value.strip()
|
|
|
312 |
try:
|
313 |
+
match = re.search(r"```json(.*?)```", raw, re.DOTALL)
|
314 |
+
if match:
|
315 |
+
json_data = json.loads(match.group(1).strip())
|
316 |
+
st.session_state.tech_results = json_data
|
317 |
+
st.session_state.tech_messages.append({"role": "assistant", "content": raw})
|
318 |
+
except Exception as e:
|
319 |
+
st.error(f"β Failed to parse assistant response: {e}")
|
320 |
break
|
321 |
except Exception as e:
|
322 |
st.error(f"β Technical Assistant Error: {e}")
|
323 |
|
324 |
with st.expander("π§ Options (Filter + Pagination)", expanded=False):
|
325 |
disciplines = sorted(set(d.get("discipline", "") for d in st.session_state.tech_results))
|
326 |
+
selected_disciplines = st.multiselect("π Filter by discipline", disciplines, default=disciplines)
|
327 |
page_size = 8
|
328 |
page = st.number_input("Page", min_value=1, step=1, value=1)
|
329 |
|
330 |
if st.session_state.tech_results:
|
331 |
st.subheader("π Results")
|
332 |
+
results = [r for r in st.session_state.tech_results if r.get("discipline") in selected_disciplines]
|
333 |
paged = results[(page - 1) * page_size : page * page_size]
|
334 |
cols = st.columns(4)
|
335 |
for i, item in enumerate(paged):
|
|
|
341 |
if not image_urls:
|
342 |
st.warning("β οΈ No image available.")
|
343 |
else:
|
344 |
+
for j, url in enumerate(image_urls):
|
345 |
+
try:
|
346 |
+
st.image(url, caption=f"Page {j+1}", use_container_width=True)
|
347 |
+
except Exception as e:
|
348 |
+
st.error(f"β Could not load image: {e}")
|
349 |
+
|
350 |
+
if st.button("πΌοΈ View All Pages", key=f"thumb_{i}"):
|
351 |
+
st.session_state.tech_lightbox = image_urls
|
352 |
+
|
353 |
+
if isinstance(st.session_state.tech_lightbox, list):
|
354 |
+
st.subheader("π Enlarged Drawing Preview")
|
355 |
+
for url in st.session_state.tech_lightbox:
|
356 |
+
st.image(url, use_container_width=True)
|
357 |
if st.button("β Close Preview"):
|
358 |
st.session_state.tech_lightbox = None
|
359 |
st.rerun()
|
360 |
else:
|
361 |
+
st.info("π No matching drawings found. Try a different prompt.")
|
362 |
+
|
363 |
+
with st.expander("π‘ Try a Prompt", expanded=False):
|
364 |
+
cols = st.columns(3)
|
365 |
+
with cols[0]:
|
366 |
+
if st.button("π Show architectural plans"):
|
367 |
+
st.session_state.tech_messages.append({"role": "user", "content": "Show me all architectural plans"})
|
368 |
+
st.rerun()
|
369 |
+
with cols[1]:
|
370 |
+
if st.button("πͺ Electrical switchboards?"):
|
371 |
+
st.session_state.tech_messages.append({"role": "user", "content": "Where are the electrical switchboards?"})
|
372 |
+
st.rerun()
|
373 |
+
with cols[2]:
|
374 |
+
if st.button("π³ Tree protection"):
|
375 |
+
st.session_state.tech_messages.append({"role": "user", "content": "Show tree protection diagrams"})
|
376 |
+
st.rerun()
|