IAMTFRMZA commited on
Commit
2a87f5c
·
verified ·
1 Parent(s): 6d838fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -220,14 +220,18 @@ 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
- if "Autopsy" in fname:
224
- folder = "Handbook Autopsy Practice Waters"
 
 
225
  else:
226
- folder = "JunqueirasBasicHistologyTextAtlas14thed.AnthonyMescher (2)"
 
227
 
228
- # Encode special characters in folder and filename
229
  encoded_folder = folder.replace(" ", "%20").replace("(", "%28").replace(")", "%29")
230
- encoded_fname = fname.replace(" ", "%20").replace("(", "%28").replace(")", "%29")
 
231
  url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
232
 
233
  try:
@@ -236,4 +240,4 @@ with tab2:
236
  img = Image.open(BytesIO(r.content))
237
  st.image(img, caption=fname, use_container_width=True)
238
  except Exception:
239
- st.warning(f"⚠️ Failed to load: {url}")
 
220
  filename_matches = re.findall(r'Image Filename:\s*(.*?\.png)', st.session_state.image_response)
221
 
222
  for fname in filename_matches:
223
+ # Dynamically extract folder name from filename prefix
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 folder (including parentheses) but NOT parentheses in filenames
232
  encoded_folder = folder.replace(" ", "%20").replace("(", "%28").replace(")", "%29")
233
+ encoded_fname = fname.replace(" ", "%20") # Leave parentheses unencoded
234
+
235
  url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
236
 
237
  try:
 
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}")