IAMTFRMZA commited on
Commit
9c3e48f
·
verified ·
1 Parent(s): ae60e08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -3,7 +3,6 @@ import os
3
  import time
4
  import re
5
  import requests
6
- import json
7
  from PIL import Image
8
  from io import BytesIO
9
  from openai import OpenAI
@@ -133,13 +132,18 @@ with tab1:
133
  messages = client.beta.threads.messages.list(thread_id=st.session_state.thread_id)
134
  for m in reversed(messages.data):
135
  if m.role == "assistant":
136
- reply = m.content[0].text.value
137
- st.session_state.messages.append({"role": "assistant", "content": reply})
138
- image_matches = re.findall(
139
- r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
140
- reply
141
  )
142
- st.session_state.image_urls = image_matches
 
 
 
 
 
 
143
  break
144
  else:
145
  st.error("❌ Assistant failed to respond.")
@@ -162,7 +166,6 @@ with tab1:
162
  st.image(img, caption=f"📷 {raw_url.split('/')[-1]}", use_container_width=True)
163
  except Exception:
164
  continue
165
-
166
 
167
 
168
  # ------------------ Tab 2: Visual Reference Search ------------------
 
3
  import time
4
  import re
5
  import requests
 
6
  from PIL import Image
7
  from io import BytesIO
8
  from openai import OpenAI
 
132
  messages = client.beta.threads.messages.list(thread_id=st.session_state.thread_id)
133
  for m in reversed(messages.data):
134
  if m.role == "assistant":
135
+ reply = m.content[0].text.value.strip()
136
+ is_duplicate = any(
137
+ reply in msg["content"] or msg["content"] in reply
138
+ for msg in st.session_state.messages if msg["role"] == "assistant"
 
139
  )
140
+ if not is_duplicate:
141
+ st.session_state.messages.append({"role": "assistant", "content": reply})
142
+ image_matches = re.findall(
143
+ r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
144
+ reply
145
+ )
146
+ st.session_state.image_urls = image_matches
147
  break
148
  else:
149
  st.error("❌ Assistant failed to respond.")
 
166
  st.image(img, caption=f"📷 {raw_url.split('/')[-1]}", use_container_width=True)
167
  except Exception:
168
  continue
 
169
 
170
 
171
  # ------------------ Tab 2: Visual Reference Search ------------------