IAMTFRMZA commited on
Commit
f3dab91
·
verified ·
1 Parent(s): aa4cbcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -132,9 +132,17 @@ with chat_col:
132
  for m in reversed(messages.data):
133
  if m.role == "assistant":
134
  reply = m.content[0].text.value
135
- st.session_state.messages.append({"role": "assistant", "content": reply})
136
 
137
- # Extract GitHub raw image URLs
 
 
 
 
 
 
 
 
 
138
  image_matches = re.findall(
139
  r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
140
  reply
@@ -148,16 +156,15 @@ with chat_col:
148
  st.error(f"❌ Error: {e}")
149
 
150
  for msg in st.session_state.messages:
151
- with st.chat_message(msg["role"]):
152
  st.markdown(msg["content"], unsafe_allow_html=True)
153
 
154
- # ------------------ Image Display with Encoding Fix ------------------
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
- # Extract everything after the domain and encode each path segment
161
  if "githubusercontent.com" not in raw_url:
162
  continue
163
  _, raw_path = raw_url.split("githubusercontent.com/", 1)
@@ -165,11 +172,6 @@ with image_col:
165
  encoded_segments = [quote(seg) for seg in segments]
166
  encoded_url = "https://raw.githubusercontent.com/" + "/".join(encoded_segments)
167
 
168
- # Load and display
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}")
 
132
  for m in reversed(messages.data):
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)
140
+ st.session_state.messages.append({"role": "assistant", "content": main_answer.strip()})
141
+ st.session_state.messages.append({"role": "references", "content": references.strip()})
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
 
156
  st.error(f"❌ Error: {e}")
157
 
158
  for msg in st.session_state.messages:
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)
 
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}")