IAMTFRMZA commited on
Commit
2aeaf4a
ยท
verified ยท
1 Parent(s): 6bb3fe2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -5,7 +5,6 @@ import re
5
  import requests
6
  from PIL import Image
7
  from io import BytesIO
8
- from urllib.parse import quote
9
  from openai import OpenAI
10
 
11
  # ------------------ Authentication ------------------
@@ -134,9 +133,9 @@ with chat_col:
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,22 +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 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}")
 
5
  import requests
6
  from PIL import Image
7
  from io import BytesIO
 
8
  from openai import OpenAI
9
 
10
  # ------------------ Authentication ------------------
 
133
  reply = m.content[0].text.value
134
  st.session_state.messages.append({"role": "assistant", "content": reply})
135
 
136
+ # ๐Ÿ” Extract GitHub raw image URLs
137
  image_matches = re.findall(
138
+ r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
139
  reply
140
  )
141
  st.session_state.image_urls = image_matches
 
150
  with st.chat_message(msg["role"]):
151
  st.markdown(msg["content"], unsafe_allow_html=True)
152
 
153
+ # ------------------ Image Preview ------------------
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
+ # โœ… Directly use the raw GitHub URL as-is
160
+ r = requests.get(raw_url)
 
 
 
 
 
 
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 as e:
165
  st.error(f"โŒ Failed to load image from {raw_url}: {e}")