IAMTFRMZA commited on
Commit
d6fd777
·
verified ·
1 Parent(s): 2ed3eb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -66,7 +66,7 @@ with tab1:
66
  # Sidebar
67
  with st.sidebar:
68
  st.header("🧪 Pathology Tools")
69
-
70
  if st.button("🧹 Clear Chat"):
71
  for k in ["messages", "thread_id", "image_urls", "pending_prompt"]:
72
  st.session_state[k] = [] if k.endswith("s") else None
@@ -98,14 +98,12 @@ with tab1:
98
  st.markdown("### 💬 Ask a Pathology-Specific Question")
99
  user_input = st.chat_input("Example: What are features of squamous cell carcinoma?")
100
 
101
- # Append input or pending prompt
102
  if user_input:
103
  st.session_state.messages.append({"role": "user", "content": user_input})
104
  elif st.session_state.pending_prompt:
105
  st.session_state.messages.append({"role": "user", "content": st.session_state.pending_prompt})
106
  st.session_state.pending_prompt = None
107
 
108
- # Trigger assistant run
109
  if st.session_state.messages and st.session_state.messages[-1]["role"] == "user":
110
  try:
111
  if not st.session_state.thread_id:
@@ -135,12 +133,11 @@ with tab1:
135
  if m.role == "assistant":
136
  reply = m.content[0].text.value.strip()
137
 
138
- # De-dupe reply
139
  if not any(reply in msg["content"] or msg["content"] in reply
140
  for msg in st.session_state.messages if msg["role"] == "assistant"):
141
  st.session_state.messages.append({"role": "assistant", "content": reply})
142
 
143
- # Image detection
144
  images = re.findall(
145
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
146
  reply
@@ -153,22 +150,26 @@ with tab1:
153
  except Exception as e:
154
  st.error(f"❌ Error: {e}")
155
 
156
- # Display conversation
157
  for msg in st.session_state.messages:
158
  with st.chat_message(msg["role"]):
159
  st.markdown(msg["content"], unsafe_allow_html=True)
160
 
161
- # Optional follow-ups
162
  if st.session_state.messages and st.session_state.messages[-1]["role"] == "assistant":
163
  last = st.session_state.messages[-1]["content"]
164
- if "Some Possible Questions:" in last:
165
- questions = re.findall(r"[-•]\s*(.*)", last)
166
- if questions:
167
- st.markdown("#### 💡 Follow-Up Suggestions")
168
- for q in questions:
169
- if st.button(f"📌 {q}"):
170
- st.session_state.pending_prompt = q
171
- st.rerun()
 
 
 
 
 
172
 
173
  with image_col:
174
  if show_image and st.session_state.image_urls:
@@ -180,6 +181,7 @@ with tab1:
180
  except Exception:
181
  st.warning(f"⚠️ Failed to load image: {url}")
182
 
 
183
  # ------------------ Tab 2: Visual Reference Search ------------------
184
  with tab2:
185
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
 
66
  # Sidebar
67
  with st.sidebar:
68
  st.header("🧪 Pathology Tools")
69
+
70
  if st.button("🧹 Clear Chat"):
71
  for k in ["messages", "thread_id", "image_urls", "pending_prompt"]:
72
  st.session_state[k] = [] if k.endswith("s") else None
 
98
  st.markdown("### 💬 Ask a Pathology-Specific Question")
99
  user_input = st.chat_input("Example: What are features of squamous cell carcinoma?")
100
 
 
101
  if user_input:
102
  st.session_state.messages.append({"role": "user", "content": user_input})
103
  elif st.session_state.pending_prompt:
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:
 
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"):
138
  st.session_state.messages.append({"role": "assistant", "content": reply})
139
 
140
+ # Extract image URLs
141
  images = re.findall(
142
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
143
  reply
 
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:
170
+ if st.button(f"📌 {q}"):
171
+ st.session_state.pending_prompt = q
172
+ st.rerun()
173
 
174
  with image_col:
175
  if show_image and st.session_state.image_urls:
 
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"