IAMTFRMZA commited on
Commit
8edd282
·
verified ·
1 Parent(s): d6fd777

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -104,6 +104,7 @@ with tab1:
104
  st.session_state.messages.append({"role": "user", "content": st.session_state.pending_prompt})
105
  st.session_state.pending_prompt = None
106
 
 
107
  if st.session_state.messages and st.session_state.messages[-1]["role"] == "user":
108
  try:
109
  if not st.session_state.thread_id:
@@ -131,7 +132,20 @@ with tab1:
131
  responses = client.beta.threads.messages.list(thread_id=st.session_state.thread_id).data
132
  for m in reversed(responses):
133
  if m.role == "assistant":
134
- reply = m.content[0].text.value.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  if not any(reply in msg["content"] or msg["content"] in reply
137
  for msg in st.session_state.messages if msg["role"] == "assistant"):
@@ -150,20 +164,17 @@ with tab1:
150
  except Exception as e:
151
  st.error(f"❌ Error: {e}")
152
 
 
153
  for msg in st.session_state.messages:
154
  with st.chat_message(msg["role"]):
155
  st.markdown(msg["content"], unsafe_allow_html=True)
156
 
157
- # ✅ Follow-Up Suggestions (Questions Only)
158
- if st.session_state.messages and st.session_state.messages[-1]["role"] == "assistant":
159
- last = st.session_state.messages[-1]["content"]
160
-
161
- # Extract bullet lines that end in a question mark
162
  questions = [
163
- line.strip(" -•") for line in last.splitlines()
164
  if line.strip().startswith(("-", "•")) and line.strip().endswith("?")
165
  ]
166
-
167
  if questions:
168
  st.markdown("#### 💡 Follow-Up Suggestions")
169
  for q in questions:
@@ -181,7 +192,6 @@ with tab1:
181
  except Exception:
182
  st.warning(f"⚠️ Failed to load image: {url}")
183
 
184
-
185
  # ------------------ Tab 2: Visual Reference Search ------------------
186
  with tab2:
187
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
 
104
  st.session_state.messages.append({"role": "user", "content": st.session_state.pending_prompt})
105
  st.session_state.pending_prompt = None
106
 
107
+ # Assistant logic
108
  if st.session_state.messages and st.session_state.messages[-1]["role"] == "user":
109
  try:
110
  if not st.session_state.thread_id:
 
132
  responses = client.beta.threads.messages.list(thread_id=st.session_state.thread_id).data
133
  for m in reversed(responses):
134
  if m.role == "assistant":
135
+ full_reply = m.content[0].text.value.strip()
136
+
137
+ # ✂️ Extract and remove "Some Possible Questions"
138
+ question_block_match = re.search(
139
+ r"Some Possible Questions:\s*(.*?)(\n{2,}|Other References:|$)",
140
+ full_reply,
141
+ re.DOTALL
142
+ )
143
+ question_block = None
144
+ if question_block_match:
145
+ question_block = question_block_match.group(1)
146
+ full_reply = full_reply.replace(f"Some Possible Questions:\n{question_block}", "").strip()
147
+
148
+ reply = full_reply
149
 
150
  if not any(reply in msg["content"] or msg["content"] in reply
151
  for msg in st.session_state.messages if msg["role"] == "assistant"):
 
164
  except Exception as e:
165
  st.error(f"❌ Error: {e}")
166
 
167
+ # Display messages
168
  for msg in st.session_state.messages:
169
  with st.chat_message(msg["role"]):
170
  st.markdown(msg["content"], unsafe_allow_html=True)
171
 
172
+ # ✅ Follow-Up Suggestions (from stripped question block)
173
+ if 'question_block' in locals() and question_block:
 
 
 
174
  questions = [
175
+ line.strip(" -•") for line in question_block.splitlines()
176
  if line.strip().startswith(("-", "•")) and line.strip().endswith("?")
177
  ]
 
178
  if questions:
179
  st.markdown("#### 💡 Follow-Up Suggestions")
180
  for q in questions:
 
192
  except Exception:
193
  st.warning(f"⚠️ Failed to load image: {url}")
194
 
 
195
  # ------------------ Tab 2: Visual Reference Search ------------------
196
  with tab2:
197
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"