Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -151,23 +151,25 @@ with chat_col:
|
|
151 |
with st.chat_message(msg["role"]):
|
152 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
153 |
|
154 |
-
# ------------------ Image Preview
|
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 |
-
|
161 |
-
if
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
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"📷 {
|
|
|
171 |
except Exception as e:
|
172 |
st.error(f"❌ Failed to load image from {raw_url}: {e}")
|
173 |
-
|
|
|
151 |
with st.chat_message(msg["role"]):
|
152 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
153 |
|
154 |
+
# ------------------ Image Preview (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 |
+
# Split and encode each part of the URL after domain
|
161 |
+
if "githubusercontent.com" not in raw_url:
|
162 |
+
continue
|
163 |
+
_, raw_path = raw_url.split("githubusercontent.com/", 1)
|
164 |
+
segments = raw_path.strip().split("/")
|
165 |
+
encoded_segments = [quote(seg) for seg in segments]
|
166 |
+
encoded_url = f"https://raw.githubusercontent.com/{'/'.join(encoded_segments)}"
|
167 |
+
|
168 |
+
# Load and display image
|
169 |
r = requests.get(encoded_url)
|
170 |
r.raise_for_status()
|
171 |
img = Image.open(BytesIO(r.content))
|
172 |
+
st.image(img, caption=f"📷 {encoded_segments[-1]}", use_container_width=True)
|
173 |
+
|
174 |
except Exception as e:
|
175 |
st.error(f"❌ Failed to load image from {raw_url}: {e}")
|
|