IAMTFRMZA commited on
Commit
6bfb206
·
verified ·
1 Parent(s): af18c30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -163,6 +163,8 @@ with tab1:
163
  except Exception:
164
  continue
165
 
 
 
166
  # ------------------ Tab 2: Visual Reference Search ------------------
167
  with tab2:
168
  st.title("🔍 Visual Reference Search")
@@ -220,7 +222,7 @@ 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 prefix before _page_
224
  match = re.match(r'^(.+?)_page_', fname)
225
  if match:
226
  folder = match.group(1).strip()
@@ -228,13 +230,9 @@ with tab2:
228
  st.warning(f"⚠️ Could not determine folder for: {fname}")
229
  continue
230
 
231
- # Correct GitHub encoding: encode spaces AND parentheses
232
- encoded_folder = (
233
- folder.replace(" ", "%20")
234
- .replace("(", "%28")
235
- .replace(")", "%29")
236
- )
237
- encoded_fname = fname.replace(" ", "%20")
238
 
239
  url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
240
 
 
163
  except Exception:
164
  continue
165
 
166
+ from urllib.parse import quote # ✅ Make sure this is at the top of your file
167
+
168
  # ------------------ Tab 2: Visual Reference Search ------------------
169
  with tab2:
170
  st.title("🔍 Visual Reference Search")
 
222
  filename_matches = re.findall(r'Image Filename:\s*(.*?\.png)', st.session_state.image_response)
223
 
224
  for fname in filename_matches:
225
+ # Extract folder from filename prefix before _page_
226
  match = re.match(r'^(.+?)_page_', fname)
227
  if match:
228
  folder = match.group(1).strip()
 
230
  st.warning(f"⚠️ Could not determine folder for: {fname}")
231
  continue
232
 
233
+ # Use URL-safe encoding for both folder and filename
234
+ encoded_folder = quote(folder)
235
+ encoded_fname = quote(fname)
 
 
 
 
236
 
237
  url = f"https://raw.githubusercontent.com/AndrewLORTech/witspathologaihisto/main/{encoded_folder}/{encoded_fname}"
238