IAMTFRMZA commited on
Commit
79637d3
·
verified ·
1 Parent(s): ade236f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -139,11 +139,22 @@ with tab1:
139
  messages = client.beta.threads.messages.list(thread_id=st.session_state.thread_id)
140
  for m in reversed(messages.data):
141
  if m.role == "assistant":
142
- reply = m.content[0].text.value.strip()
143
- if not any(reply in msg["content"] or msg["content"] in reply for msg in st.session_state.messages if msg["role"] == "assistant"):
144
- st.session_state.messages.append({"role": "assistant", "content": reply})
145
-
146
- image_matches = re.findall(r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png', reply)
 
 
 
 
 
 
 
 
 
 
 
147
  if image_matches:
148
  st.session_state.image_url = image_matches[0]
149
  st.session_state.image_updated = True
@@ -168,6 +179,7 @@ with tab1:
168
  except Exception as e:
169
  st.error(f"🖼️ Failed to load image: {e}")
170
 
 
171
  # ------------------ Tab 2: Visual Reference Search ------------------
172
  with tab2:
173
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
 
139
  messages = client.beta.threads.messages.list(thread_id=st.session_state.thread_id)
140
  for m in reversed(messages.data):
141
  if m.role == "assistant":
142
+ raw_reply = m.content[0].text.value.strip()
143
+
144
+ # Clean formatting and strip noise
145
+ cleaned_reply = re.sub(r'\[source[\d\.]+\]', '', raw_reply)
146
+ cleaned_reply = re.sub(r'\n{3,}', '\n\n', cleaned_reply)
147
+ cleaned_reply = re.sub(r'\*\*+', '**', cleaned_reply)
148
+ cleaned_reply = re.sub(r'(?<=\n)([-*]\s[^\n]+)', r'\1\n', cleaned_reply)
149
+ cleaned_reply = cleaned_reply.strip()
150
+
151
+ if not any(cleaned_reply in msg["content"] or msg["content"] in cleaned_reply for msg in st.session_state.messages if msg["role"] == "assistant"):
152
+ st.session_state.messages.append({"role": "assistant", "content": cleaned_reply})
153
+
154
+ image_matches = re.findall(
155
+ r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
156
+ cleaned_reply
157
+ )
158
  if image_matches:
159
  st.session_state.image_url = image_matches[0]
160
  st.session_state.image_updated = True
 
179
  except Exception as e:
180
  st.error(f"🖼️ Failed to load image: {e}")
181
 
182
+
183
  # ------------------ Tab 2: Visual Reference Search ------------------
184
  with tab2:
185
  ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"