Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -162,6 +162,7 @@ with tab1:
|
|
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,7 +220,7 @@ with tab2:
|
|
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
|
223 |
match = re.match(r'^(.+?)_page_', fname)
|
224 |
if match:
|
225 |
folder = match.group(1).strip()
|
@@ -227,17 +228,18 @@ with tab2:
|
|
227 |
st.warning(f"β οΈ Could not determine folder for: {fname}")
|
228 |
continue
|
229 |
|
230 |
-
#
|
231 |
-
encoded_folder =
|
|
|
|
|
|
|
|
|
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()
|
|
|
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 |
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 |
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 |
|
|
|
241 |
st.markdown(f"π [View image directly]({url})")
|
242 |
|
|
|
243 |
try:
|
244 |
r = requests.get(url, timeout=5)
|
245 |
r.raise_for_status()
|