IAMTFRMZA commited on
Commit
0c9e6cc
·
verified ·
1 Parent(s): b1d4a6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
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
- # Extract folder from filename prefix (before _page_)
224
- parts = fname.split("_page_")
225
- if len(parts) > 1:
226
- folder = parts[0]
227
  else:
228
  st.warning(f"⚠️ Could not determine folder for: {fname}")
229
  continue
230
 
231
- # Only encode spaces leave parentheses untouched to match GitHub structure
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
+