Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -163,7 +163,7 @@ with tab1:
|
|
163 |
except Exception:
|
164 |
continue
|
165 |
|
166 |
-
# ------------------ Tab 2: Visual Search ------------------
|
167 |
with tab2:
|
168 |
st.title("🔍 Visual Reference Search")
|
169 |
user_query = st.text_input("Enter keyword to search images (e.g. ovary, thyroid, mitosis)")
|
@@ -220,24 +220,29 @@ with tab2:
|
|
220 |
filename_matches = re.findall(r'Image Filename:\s*(.*?\.png)', st.session_state.image_response)
|
221 |
|
222 |
for fname in filename_matches:
|
223 |
-
#
|
224 |
-
|
225 |
-
if
|
226 |
-
folder =
|
227 |
else:
|
228 |
st.warning(f"⚠️ Could not determine folder for: {fname}")
|
229 |
continue
|
230 |
|
231 |
-
#
|
232 |
encoded_folder = folder.replace(" ", "%20")
|
233 |
encoded_fname = fname.replace(" ", "%20")
|
234 |
|
235 |
url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
|
236 |
|
|
|
|
|
|
|
237 |
try:
|
238 |
r = requests.get(url, timeout=5)
|
239 |
r.raise_for_status()
|
240 |
img = Image.open(BytesIO(r.content))
|
241 |
st.image(img, caption=fname, use_container_width=True)
|
242 |
-
except Exception:
|
243 |
st.warning(f"⚠️ Failed to load: {url}")
|
|
|
|
|
|
163 |
except Exception:
|
164 |
continue
|
165 |
|
166 |
+
# ------------------ Tab 2: Visual Reference Search ------------------
|
167 |
with tab2:
|
168 |
st.title("🔍 Visual Reference Search")
|
169 |
user_query = st.text_input("Enter keyword to search images (e.g. ovary, thyroid, mitosis)")
|
|
|
220 |
filename_matches = re.findall(r'Image Filename:\s*(.*?\.png)', st.session_state.image_response)
|
221 |
|
222 |
for fname in filename_matches:
|
223 |
+
# Safely extract folder by splitting BEFORE the _page_ part
|
224 |
+
match = re.match(r'^(.+?)_page_', fname)
|
225 |
+
if match:
|
226 |
+
folder = match.group(1)
|
227 |
else:
|
228 |
st.warning(f"⚠️ Could not determine folder for: {fname}")
|
229 |
continue
|
230 |
|
231 |
+
# Encode only spaces – DO NOT encode parentheses or underscores
|
232 |
encoded_folder = folder.replace(" ", "%20")
|
233 |
encoded_fname = fname.replace(" ", "%20")
|
234 |
|
235 |
url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
|
236 |
|
237 |
+
# Optional: show the raw image URL for debugging
|
238 |
+
st.markdown(f"🔗 [View image directly]({url})")
|
239 |
+
|
240 |
try:
|
241 |
r = requests.get(url, timeout=5)
|
242 |
r.raise_for_status()
|
243 |
img = Image.open(BytesIO(r.content))
|
244 |
st.image(img, caption=fname, use_container_width=True)
|
245 |
+
except Exception as e:
|
246 |
st.warning(f"⚠️ Failed to load: {url}")
|
247 |
+
st.error(f"🛑 Error: {str(e)}")
|
248 |
+
|