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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -162,7 +162,6 @@ with tab1:
162
  st.image(img, caption=f"πŸ“· {raw_url.split('/')[-1]}", use_container_width=True)
163
  except Exception:
164
  continue
165
-
166
  # ------------------ Tab 2: Visual Reference Search ------------------
167
  with tab2:
168
  st.title("πŸ” Visual Reference Search")
@@ -220,23 +219,25 @@ 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
- # 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()
 
162
  st.image(img, caption=f"πŸ“· {raw_url.split('/')[-1]}", use_container_width=True)
163
  except Exception:
164
  continue
 
165
  # ------------------ Tab 2: Visual Reference Search ------------------
166
  with tab2:
167
  st.title("πŸ” Visual Reference Search")
 
219
  filename_matches = re.findall(r'Image Filename:\s*(.*?\.png)', st.session_state.image_response)
220
 
221
  for fname in filename_matches:
222
+ # Extract folder name from filename prefix (clean + safe)
223
  match = re.match(r'^(.+?)_page_', fname)
224
  if match:
225
+ folder = match.group(1).strip()
226
  else:
227
  st.warning(f"⚠️ Could not determine folder for: {fname}")
228
  continue
229
 
230
+ # Encode only spaces – parentheses/underscores remain as-is
231
  encoded_folder = folder.replace(" ", "%20")
232
  encoded_fname = fname.replace(" ", "%20")
233
 
234
+ # Final raw GitHub URL
235
  url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
236
 
237
+ # Debug: show link
238
  st.markdown(f"πŸ”— [View image directly]({url})")
239
 
240
+ # Try loading and displaying image
241
  try:
242
  r = requests.get(url, timeout=5)
243
  r.raise_for_status()