IAMTFRMZA commited on
Commit
328d090
·
verified ·
1 Parent(s): 024d945

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
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 ------------------
@@ -133,7 +132,7 @@ with chat_col:
133
  if m.role == "assistant":
134
  reply = m.content[0].text.value
135
 
136
- # ✂️ Split output into main and references (if structured this way)
137
  split_marker = "---"
138
  if split_marker in reply:
139
  main_answer, references = reply.split(split_marker, 1)
@@ -142,7 +141,7 @@ with chat_col:
142
  else:
143
  st.session_state.messages.append({"role": "assistant", "content": reply})
144
 
145
- # Extract GitHub image URLs
146
  image_matches = re.findall(
147
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
148
  reply
@@ -159,19 +158,14 @@ with chat_col:
159
  with st.chat_message("assistant" if msg["role"] != "references" else "📄"):
160
  st.markdown(msg["content"], unsafe_allow_html=True)
161
 
162
- # ------------------ Image Viewer (Scrollable Format) ------------------
163
  with image_col:
164
  if show_image and st.session_state.image_urls:
165
  st.markdown("### 🖼️ Slide Previews")
166
  for i, raw_url in enumerate(st.session_state.image_urls):
167
  try:
168
- if "githubusercontent.com" not in raw_url:
169
- continue
170
- _, raw_path = raw_url.split("githubusercontent.com/", 1)
171
- segments = raw_path.strip().split("/")
172
- encoded_segments = [quote(seg) for seg in segments]
173
- encoded_url = "https://raw.githubusercontent.com/" + "/".join(encoded_segments)
174
-
175
- st.image(encoded_url, caption=f"Slide {i + 1}", use_column_width=True)
176
  except Exception as e:
177
  st.error(f"❌ Failed to load image: {e}")
 
5
  import requests
6
  from PIL import Image
7
  from io import BytesIO
 
8
  from openai import OpenAI
9
 
10
  # ------------------ Authentication ------------------
 
132
  if m.role == "assistant":
133
  reply = m.content[0].text.value
134
 
135
+ # ✂️ Split output into main and references
136
  split_marker = "---"
137
  if split_marker in reply:
138
  main_answer, references = reply.split(split_marker, 1)
 
141
  else:
142
  st.session_state.messages.append({"role": "assistant", "content": reply})
143
 
144
+ # Extract GitHub image URLs directly
145
  image_matches = re.findall(
146
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
147
  reply
 
158
  with st.chat_message("assistant" if msg["role"] != "references" else "📄"):
159
  st.markdown(msg["content"], unsafe_allow_html=True)
160
 
161
+ # ------------------ Image Viewer ------------------
162
  with image_col:
163
  if show_image and st.session_state.image_urls:
164
  st.markdown("### 🖼️ Slide Previews")
165
  for i, raw_url in enumerate(st.session_state.image_urls):
166
  try:
167
+ # Optional: Log image URLs for debugging
168
+ # st.write(f"Image URL {i+1}: {raw_url}")
169
+ st.image(raw_url, caption=f"Slide {i + 1}", use_container_width=True)
 
 
 
 
 
170
  except Exception as e:
171
  st.error(f"❌ Failed to load image: {e}")