IAMTFRMZA commited on
Commit
29d68fa
Β·
verified Β·
1 Parent(s): ba9c72e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -55,7 +55,6 @@ tab1, tab2 = st.tabs(["πŸ“‘ Contract", "πŸ“ Technical"])
55
  with tab1:
56
  ASSISTANT_ID = "asst_KsQRedoJUnEeStzfox1o06lO"
57
 
58
- # Correct session state initialization
59
  if "messages" not in st.session_state:
60
  st.session_state.messages = []
61
  if "thread_id" not in st.session_state:
@@ -67,7 +66,6 @@ with tab1:
67
  if "pending_prompt" not in st.session_state:
68
  st.session_state.pending_prompt = None
69
 
70
- # Sidebar tools
71
  with st.sidebar:
72
  st.header("ℹ️ Contract Tools")
73
  if st.button("🧹 Clear Chat"):
@@ -79,7 +77,6 @@ with tab1:
79
  st.rerun()
80
 
81
  show_image = st.toggle("πŸ“‘ Show Page Image", value=True)
82
-
83
  keyword = st.text_input("Search by Keyword", placeholder="e.g. defects, WHS, delay")
84
  if st.button("πŸ”Ž Search Keyword") and keyword:
85
  st.session_state.pending_prompt = f"Find clauses or references related to: {keyword}"
@@ -112,7 +109,6 @@ with tab1:
112
  if action != actions[0]:
113
  st.session_state.pending_prompt = action
114
 
115
- # Chat + Image layout
116
  chat_col, image_col = st.columns([2, 1])
117
  with chat_col:
118
  st.markdown("### 🧠 Ask a Document-Specific Question")
@@ -230,7 +226,7 @@ with tab2:
230
  content = msg.content[0].text.value
231
  st.session_state.tech_messages.append({"role": "assistant", "content": content})
232
  try:
233
- st.session_state.tech_results = json.loads(content.strip("json "))
234
  except:
235
  st.session_state.tech_results = []
236
  break
@@ -252,10 +248,20 @@ with tab2:
252
  with cols[i % 4]:
253
  st.markdown(f"**πŸ“ {item['drawing_number']} ({item['discipline']})**")
254
  st.caption(item.get("summary", ""))
255
- for url in item.get("images", [])[:1]:
 
 
 
 
 
 
 
 
 
 
 
256
  if st.button("πŸ–ΌοΈ View Drawing Details", key=f"thumb_{i}"):
257
  st.session_state.tech_lightbox = url
258
- st.image(url, caption=f"{item['drawing_number']} - Page 1", use_container_width=True)
259
 
260
  if st.session_state.tech_lightbox:
261
  st.image(st.session_state.tech_lightbox, caption="πŸ” Enlarged Drawing Preview", use_container_width=True)
@@ -265,4 +271,4 @@ with tab2:
265
  else:
266
  for msg in st.session_state.tech_messages:
267
  with st.chat_message(msg["role"]):
268
- st.markdown(msg["content"], unsafe_allow_html=True)
 
55
  with tab1:
56
  ASSISTANT_ID = "asst_KsQRedoJUnEeStzfox1o06lO"
57
 
 
58
  if "messages" not in st.session_state:
59
  st.session_state.messages = []
60
  if "thread_id" not in st.session_state:
 
66
  if "pending_prompt" not in st.session_state:
67
  st.session_state.pending_prompt = None
68
 
 
69
  with st.sidebar:
70
  st.header("ℹ️ Contract Tools")
71
  if st.button("🧹 Clear Chat"):
 
77
  st.rerun()
78
 
79
  show_image = st.toggle("πŸ“‘ Show Page Image", value=True)
 
80
  keyword = st.text_input("Search by Keyword", placeholder="e.g. defects, WHS, delay")
81
  if st.button("πŸ”Ž Search Keyword") and keyword:
82
  st.session_state.pending_prompt = f"Find clauses or references related to: {keyword}"
 
109
  if action != actions[0]:
110
  st.session_state.pending_prompt = action
111
 
 
112
  chat_col, image_col = st.columns([2, 1])
113
  with chat_col:
114
  st.markdown("### 🧠 Ask a Document-Specific Question")
 
226
  content = msg.content[0].text.value
227
  st.session_state.tech_messages.append({"role": "assistant", "content": content})
228
  try:
229
+ st.session_state.tech_results = json.loads(content.strip("`json "))
230
  except:
231
  st.session_state.tech_results = []
232
  break
 
248
  with cols[i % 4]:
249
  st.markdown(f"**πŸ“ {item['drawing_number']} ({item['discipline']})**")
250
  st.caption(item.get("summary", ""))
251
+
252
+ image_urls = item.get("images", [])
253
+ if not image_urls:
254
+ st.warning("⚠️ No image available.")
255
+ else:
256
+ url = image_urls[0]
257
+ st.caption(f"πŸ”— Image URL: {url}")
258
+ try:
259
+ st.image(url, caption=f"{item['drawing_number']} - Page 1", use_container_width=True)
260
+ except Exception as e:
261
+ st.error(f"❌ Could not load image: {e}")
262
+
263
  if st.button("πŸ–ΌοΈ View Drawing Details", key=f"thumb_{i}"):
264
  st.session_state.tech_lightbox = url
 
265
 
266
  if st.session_state.tech_lightbox:
267
  st.image(st.session_state.tech_lightbox, caption="πŸ” Enlarged Drawing Preview", use_container_width=True)
 
271
  else:
272
  for msg in st.session_state.tech_messages:
273
  with st.chat_message(msg["role"]):
274
+ st.markdown(msg["content"], unsafe_allow_html=True)