IAMTFRMZA commited on
Commit
41c50e2
·
verified ·
1 Parent(s): f74224d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import os
3
  import time
4
  import re
 
5
  from openai import OpenAI
6
 
7
  # ------------------ Authentication ------------------
@@ -138,14 +139,12 @@ with chat_col:
138
  else:
139
  st.session_state.messages.append({"role": "assistant", "content": reply})
140
 
141
- # Extract GitHub image URLs
142
  image_matches = re.findall(
143
- r'https://github\.com/AndrewLORTech/witspathologai/blob/main/[^\s\n]+\.png',
144
  reply
145
  )
146
- # Transform to raw.githubusercontent.com URLs
147
- raw_urls = [url.replace("github.com", "raw.githubusercontent.com").replace("/blob/", "/") for url in image_matches]
148
- st.session_state.image_urls = raw_urls
149
  break
150
  else:
151
  st.error("❌ Assistant failed to respond.")
@@ -157,12 +156,17 @@ with chat_col:
157
  with st.chat_message("assistant" if msg["role"] != "references" else "📄"):
158
  st.markdown(msg["content"], unsafe_allow_html=True)
159
 
160
- # ------------------ Image Viewer ------------------
161
  with image_col:
162
  if show_image and st.session_state.image_urls:
163
  st.markdown("### 🖼️ Slide Previews")
164
  for i, raw_url in enumerate(st.session_state.image_urls):
165
  try:
166
- st.image(raw_url, caption=f"Slide {i + 1}", use_container_width=True)
 
 
 
 
 
167
  except Exception as e:
168
- st.error(f"❌ Failed to load image: {e}")
 
2
  import os
3
  import time
4
  import re
5
+ from urllib.parse import quote
6
  from openai import OpenAI
7
 
8
  # ------------------ Authentication ------------------
 
139
  else:
140
  st.session_state.messages.append({"role": "assistant", "content": reply})
141
 
142
+ # Extract raw GitHub image URLs
143
  image_matches = re.findall(
144
+ r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
145
  reply
146
  )
147
+ st.session_state.image_urls = image_matches
 
 
148
  break
149
  else:
150
  st.error("❌ Assistant failed to respond.")
 
156
  with st.chat_message("assistant" if msg["role"] != "references" else "📄"):
157
  st.markdown(msg["content"], unsafe_allow_html=True)
158
 
159
+ # ------------------ Image Viewer (with encoded URLs) ------------------
160
  with image_col:
161
  if show_image and st.session_state.image_urls:
162
  st.markdown("### 🖼️ Slide Previews")
163
  for i, raw_url in enumerate(st.session_state.image_urls):
164
  try:
165
+ if "raw.githubusercontent.com" in raw_url:
166
+ base = "https://raw.githubusercontent.com/"
167
+ path = raw_url.replace(base, "")
168
+ encoded_path = "/".join(quote(p) for p in path.split("/"))
169
+ encoded_url = base + encoded_path
170
+ st.image(encoded_url, caption=f"Slide {i + 1}", use_container_width=True)
171
  except Exception as e:
172
+ st.error(f"❌ Failed to load image {i + 1}: {e}")