IAMTFRMZA commited on
Commit
5451697
·
verified ·
1 Parent(s): f3c5e51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
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 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
-
 
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}")