Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -166,9 +166,10 @@ with tab1:
|
|
166 |
|
167 |
|
168 |
# ------------------ Tab 2: Visual Reference Search ------------------
|
169 |
-
|
170 |
with tab2:
|
171 |
-
ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO" # Your
|
|
|
|
|
172 |
if "image_thread_id" not in st.session_state:
|
173 |
st.session_state.image_thread_id = None
|
174 |
if "image_response" not in st.session_state:
|
@@ -178,7 +179,7 @@ with tab2:
|
|
178 |
if "image_lightbox" not in st.session_state:
|
179 |
st.session_state.image_lightbox = None
|
180 |
|
181 |
-
# User input
|
182 |
image_input = st.chat_input("Ask for histology visual references (e.g. ovary histology, mitosis)")
|
183 |
if image_input:
|
184 |
st.session_state.image_response = None
|
@@ -218,18 +219,24 @@ with tab2:
|
|
218 |
response_text = msg.content[0].text.value
|
219 |
st.session_state.image_response = response_text
|
220 |
|
221 |
-
#
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
break
|
229 |
except Exception as e:
|
230 |
st.error(f"❌ Visual Assistant Error: {e}")
|
231 |
|
232 |
-
#
|
233 |
text_col, image_col = st.columns([2, 1])
|
234 |
|
235 |
with text_col:
|
@@ -241,7 +248,7 @@ with tab2:
|
|
241 |
if st.session_state.image_results:
|
242 |
st.markdown("### 🖼️ Image Preview(s)")
|
243 |
for i, item in enumerate(st.session_state.image_results):
|
244 |
-
image_url = item.get("image")
|
245 |
if image_url:
|
246 |
try:
|
247 |
st.image(image_url, caption=image_url.split("/")[-1], use_container_width=True)
|
|
|
166 |
|
167 |
|
168 |
# ------------------ Tab 2: Visual Reference Search ------------------
|
|
|
169 |
with tab2:
|
170 |
+
ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO" # Your visual reference assistant ID
|
171 |
+
|
172 |
+
# Session states
|
173 |
if "image_thread_id" not in st.session_state:
|
174 |
st.session_state.image_thread_id = None
|
175 |
if "image_response" not in st.session_state:
|
|
|
179 |
if "image_lightbox" not in st.session_state:
|
180 |
st.session_state.image_lightbox = None
|
181 |
|
182 |
+
# User input
|
183 |
image_input = st.chat_input("Ask for histology visual references (e.g. ovary histology, mitosis)")
|
184 |
if image_input:
|
185 |
st.session_state.image_response = None
|
|
|
219 |
response_text = msg.content[0].text.value
|
220 |
st.session_state.image_response = response_text
|
221 |
|
222 |
+
# 🔍 Robustly extract "Image URL" entries
|
223 |
+
lines = response_text.splitlines()
|
224 |
+
image_urls = []
|
225 |
+
for i, line in enumerate(lines):
|
226 |
+
if "Image URL:" in line:
|
227 |
+
url = line.split("Image URL:")[-1].strip()
|
228 |
+
if not url.startswith("http") and i + 1 < len(lines):
|
229 |
+
next_line = lines[i + 1].strip()
|
230 |
+
if next_line.startswith("http"):
|
231 |
+
url = next_line
|
232 |
+
if url.startswith("http"):
|
233 |
+
image_urls.append(url)
|
234 |
+
st.session_state.image_results = [{"image": url} for url in image_urls]
|
235 |
break
|
236 |
except Exception as e:
|
237 |
st.error(f"❌ Visual Assistant Error: {e}")
|
238 |
|
239 |
+
# Layout split
|
240 |
text_col, image_col = st.columns([2, 1])
|
241 |
|
242 |
with text_col:
|
|
|
248 |
if st.session_state.image_results:
|
249 |
st.markdown("### 🖼️ Image Preview(s)")
|
250 |
for i, item in enumerate(st.session_state.image_results):
|
251 |
+
image_url = item.get("image")
|
252 |
if image_url:
|
253 |
try:
|
254 |
st.image(image_url, caption=image_url.split("/")[-1], use_container_width=True)
|