Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -134,9 +134,9 @@ with chat_col:
|
|
134 |
reply = m.content[0].text.value
|
135 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
136 |
|
137 |
-
#
|
138 |
image_matches = re.findall(
|
139 |
-
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[
|
140 |
reply
|
141 |
)
|
142 |
st.session_state.image_urls = image_matches
|
@@ -151,15 +151,23 @@ with chat_col:
|
|
151 |
with st.chat_message(msg["role"]):
|
152 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
153 |
|
154 |
-
# ------------------
|
155 |
with image_col:
|
156 |
if show_image and st.session_state.image_urls:
|
157 |
st.markdown("### 🖼️ Slide Previews")
|
158 |
-
for
|
159 |
try:
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
r.raise_for_status()
|
162 |
img = Image.open(BytesIO(r.content))
|
163 |
-
st.image(img, caption=f"📷 {
|
164 |
except Exception as e:
|
165 |
-
st.error(f"❌ Failed to load image from {
|
|
|
|
134 |
reply = m.content[0].text.value
|
135 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
136 |
|
137 |
+
# 🔍 Extract all GitHub image URLs
|
138 |
image_matches = re.findall(
|
139 |
+
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
|
140 |
reply
|
141 |
)
|
142 |
st.session_state.image_urls = image_matches
|
|
|
151 |
with st.chat_message(msg["role"]):
|
152 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
153 |
|
154 |
+
# ------------------ Image Preview with Safe Encoding ------------------
|
155 |
with image_col:
|
156 |
if show_image and st.session_state.image_urls:
|
157 |
st.markdown("### 🖼️ Slide Previews")
|
158 |
+
for raw_url in st.session_state.image_urls:
|
159 |
try:
|
160 |
+
url_parts = raw_url.split("githubusercontent.com/")
|
161 |
+
if len(url_parts) == 2:
|
162 |
+
encoded_path = quote(url_parts[1])
|
163 |
+
encoded_url = f"https://raw.githubusercontent.com/{encoded_path}"
|
164 |
+
else:
|
165 |
+
encoded_url = raw_url
|
166 |
+
|
167 |
+
r = requests.get(encoded_url)
|
168 |
r.raise_for_status()
|
169 |
img = Image.open(BytesIO(r.content))
|
170 |
+
st.image(img, caption=f"📷 {encoded_url.split('/')[-1]}", use_container_width=True)
|
171 |
except Exception as e:
|
172 |
+
st.error(f"❌ Failed to load image from {raw_url}: {e}")
|
173 |
+
|