IAMTFRMZA commited on
Commit
fe6caf9
·
verified ·
1 Parent(s): 2621f7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -3,7 +3,6 @@ import os
3
  import time
4
  import re
5
  import requests
6
- import urllib.parse
7
  from PIL import Image
8
  from io import BytesIO
9
  from openai import OpenAI
@@ -134,7 +133,7 @@ with chat_col:
134
  reply = m.content[0].text.value
135
  st.session_state.messages.append({"role": "assistant", "content": reply})
136
 
137
- # Extract raw GitHub image URLs
138
  image_matches = re.findall(
139
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
140
  reply
@@ -151,23 +150,16 @@ with chat_col:
151
  with st.chat_message(msg["role"]):
152
  st.markdown(msg["content"], unsafe_allow_html=True)
153
 
154
- # ------------------ Image Preview (Smart URL 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
- if raw_url.startswith("https://raw.githubusercontent.com/"):
161
- base_url = "https://raw.githubusercontent.com/"
162
- path = raw_url[len(base_url):]
163
- encoded_path = urllib.parse.quote(path, safe="/")
164
- encoded_url = base_url + encoded_path
165
- else:
166
- encoded_url = raw_url
167
-
168
- r = requests.get(encoded_url, timeout=5)
169
  r.raise_for_status()
170
  img = Image.open(BytesIO(r.content))
171
- st.image(img, caption=f"📷 {encoded_url.split('/')[-1]}", use_container_width=True)
172
  except Exception:
173
  continue # Silently skip broken images
 
3
  import time
4
  import re
5
  import requests
 
6
  from PIL import Image
7
  from io import BytesIO
8
  from openai import OpenAI
 
133
  reply = m.content[0].text.value
134
  st.session_state.messages.append({"role": "assistant", "content": reply})
135
 
136
+ # Extract GitHub raw image URLs (already encoded by assistant)
137
  image_matches = re.findall(
138
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
139
  reply
 
150
  with st.chat_message(msg["role"]):
151
  st.markdown(msg["content"], unsafe_allow_html=True)
152
 
153
+ # ------------------ Image Preview (No Re-Encoding) ------------------
154
  with image_col:
155
  if show_image and st.session_state.image_urls:
156
  st.markdown("### 🖼️ Slide Previews")
157
  for raw_url in st.session_state.image_urls:
158
  try:
159
+ # ✅ Use assistant's already-encoded URL directly
160
+ r = requests.get(raw_url, timeout=5)
 
 
 
 
 
 
 
161
  r.raise_for_status()
162
  img = Image.open(BytesIO(r.content))
163
+ st.image(img, caption=f"📷 {raw_url.split('/')[-1]}", use_container_width=True)
164
  except Exception:
165
  continue # Silently skip broken images