IAMTFRMZA commited on
Commit
9836b6d
Β·
verified Β·
1 Parent(s): 8b180a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -116,13 +116,17 @@ with tab1:
116
 
117
  with st.spinner("πŸ”¬ Analyzing..."):
118
  while True:
119
- status = client.beta.threads.runs.retrieve(thread_id=st.session_state.thread_id, run_id=run.id)
 
 
120
  if status.status in ("completed", "failed", "cancelled"):
121
  break
122
  time.sleep(1)
123
 
124
  if status.status == "completed":
125
- responses = client.beta.threads.messages.list(thread_id=st.session_state.thread_id).data
 
 
126
  for m in reversed(responses):
127
  if m.role == "assistant":
128
  reply = m.content[0].text.value.strip()
@@ -130,6 +134,7 @@ with tab1:
130
  for msg in st.session_state.messages if msg["role"] == "assistant"):
131
  st.session_state.messages.append({"role": "assistant", "content": reply})
132
 
 
133
  images = re.findall(
134
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
135
  reply
@@ -142,20 +147,27 @@ with tab1:
142
  except Exception as e:
143
  st.error(f"❌ Error: {e}")
144
 
 
145
  for msg in st.session_state.messages:
146
  with st.chat_message(msg["role"]):
147
  st.markdown(msg["content"], unsafe_allow_html=True)
148
 
 
149
  if st.session_state.messages and st.session_state.messages[-1]["role"] == "assistant":
150
  last = st.session_state.messages[-1]["content"]
151
  if "Some Possible Questions:" in last:
152
- questions = re.findall(r"[-β€’]\s*(.*)", last)
 
 
 
153
  if questions:
154
  st.markdown("#### πŸ’‘ Follow-Up Suggestions")
155
  for q in questions:
156
  if st.button(f"πŸ“Œ {q}"):
157
  st.session_state.pending_prompt = q
158
  st.rerun()
 
 
159
 
160
  with image_col:
161
  if show_image and st.session_state.image_urls:
@@ -167,7 +179,6 @@ with tab1:
167
  except Exception:
168
  st.warning(f"⚠️ Failed to load image: {url}")
169
 
170
-
171
  # ------------------ Tab 2: Visual Reference Search ------------------
172
  with tab2:
173
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
 
116
 
117
  with st.spinner("πŸ”¬ Analyzing..."):
118
  while True:
119
+ status = client.beta.threads.runs.retrieve(
120
+ thread_id=st.session_state.thread_id, run_id=run.id
121
+ )
122
  if status.status in ("completed", "failed", "cancelled"):
123
  break
124
  time.sleep(1)
125
 
126
  if status.status == "completed":
127
+ responses = client.beta.threads.messages.list(
128
+ thread_id=st.session_state.thread_id
129
+ ).data
130
  for m in reversed(responses):
131
  if m.role == "assistant":
132
  reply = m.content[0].text.value.strip()
 
134
  for msg in st.session_state.messages if msg["role"] == "assistant"):
135
  st.session_state.messages.append({"role": "assistant", "content": reply})
136
 
137
+ # Extract image URLs from response
138
  images = re.findall(
139
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
140
  reply
 
147
  except Exception as e:
148
  st.error(f"❌ Error: {e}")
149
 
150
+ # Display messages
151
  for msg in st.session_state.messages:
152
  with st.chat_message(msg["role"]):
153
  st.markdown(msg["content"], unsafe_allow_html=True)
154
 
155
+ # Display follow-up questions
156
  if st.session_state.messages and st.session_state.messages[-1]["role"] == "assistant":
157
  last = st.session_state.messages[-1]["content"]
158
  if "Some Possible Questions:" in last:
159
+ # Filter only lines that are actual questions
160
+ all_lines = re.findall(r"[-β€’]\s*(.*)", last)
161
+ questions = [line for line in all_lines if line.strip().endswith("?")]
162
+
163
  if questions:
164
  st.markdown("#### πŸ’‘ Follow-Up Suggestions")
165
  for q in questions:
166
  if st.button(f"πŸ“Œ {q}"):
167
  st.session_state.pending_prompt = q
168
  st.rerun()
169
+ else:
170
+ st.markdown("#### πŸ’‘ No follow-up questions detected in the assistant's response.")
171
 
172
  with image_col:
173
  if show_image and st.session_state.image_urls:
 
179
  except Exception:
180
  st.warning(f"⚠️ Failed to load image: {url}")
181
 
 
182
  # ------------------ Tab 2: Visual Reference Search ------------------
183
  with tab2:
184
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"