Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -213,36 +213,22 @@ with tab2:
|
|
213 |
except Exception as e:
|
214 |
st.error(f"Error: {e}")
|
215 |
|
216 |
-
# Render assistant response
|
217 |
if st.session_state.image_response:
|
218 |
st.markdown("### 🧠 Assistant Response")
|
219 |
st.markdown(st.session_state.image_response, unsafe_allow_html=True)
|
220 |
|
221 |
-
# Extract
|
222 |
-
|
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()
|
229 |
-
else:
|
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 |
|
|
|
239 |
st.markdown(f"🔗 [View image directly]({url})")
|
240 |
|
241 |
try:
|
242 |
r = requests.get(url, timeout=5)
|
243 |
r.raise_for_status()
|
244 |
img = Image.open(BytesIO(r.content))
|
245 |
-
st.image(img, caption=
|
246 |
except Exception as e:
|
247 |
st.warning(f"⚠️ Failed to load: {url}")
|
248 |
st.error(f"🛑 Error: {str(e)}")
|
|
|
213 |
except Exception as e:
|
214 |
st.error(f"Error: {e}")
|
215 |
|
216 |
+
# Render assistant response and display images using 'Image URL' field
|
217 |
if st.session_state.image_response:
|
218 |
st.markdown("### 🧠 Assistant Response")
|
219 |
st.markdown(st.session_state.image_response, unsafe_allow_html=True)
|
220 |
|
221 |
+
# Extract full GitHub URLs from assistant output
|
222 |
+
url_matches = re.findall(r'Image URL:\s*(https?://[^\s]+)', st.session_state.image_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
+
for url in url_matches:
|
225 |
st.markdown(f"🔗 [View image directly]({url})")
|
226 |
|
227 |
try:
|
228 |
r = requests.get(url, timeout=5)
|
229 |
r.raise_for_status()
|
230 |
img = Image.open(BytesIO(r.content))
|
231 |
+
st.image(img, caption=url.split("/")[-1], use_container_width=True)
|
232 |
except Exception as e:
|
233 |
st.warning(f"⚠️ Failed to load: {url}")
|
234 |
st.error(f"🛑 Error: {str(e)}")
|