Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ if not OPENAI_API_KEY:
|
|
48 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
49 |
|
50 |
# ------------------ Assistant Configuration ------------------
|
51 |
-
ASSISTANT_ID = "asst_jXDSjCG8LI4HEaFEcjFVq8KB" # Replace with your
|
52 |
|
53 |
# ------------------ Session State ------------------
|
54 |
if "messages" not in st.session_state:
|
@@ -133,7 +133,7 @@ with chat_col:
|
|
133 |
if m.role == "assistant":
|
134 |
reply = m.content[0].text.value
|
135 |
|
136 |
-
# ✂️
|
137 |
split_marker = "---"
|
138 |
if split_marker in reply:
|
139 |
main_answer, references = reply.split(split_marker, 1)
|
@@ -142,7 +142,7 @@ with chat_col:
|
|
142 |
else:
|
143 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
144 |
|
145 |
-
# Extract GitHub image
|
146 |
image_matches = re.findall(
|
147 |
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
|
148 |
reply
|
@@ -159,11 +159,29 @@ 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 |
-
# ------------------
|
163 |
with image_col:
|
164 |
if show_image and st.session_state.image_urls:
|
165 |
st.markdown("### 🖼️ Slide Previews")
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
try:
|
168 |
if "githubusercontent.com" not in raw_url:
|
169 |
continue
|
@@ -172,6 +190,8 @@ with image_col:
|
|
172 |
encoded_segments = [quote(seg) for seg in segments]
|
173 |
encoded_url = "https://raw.githubusercontent.com/" + "/".join(encoded_segments)
|
174 |
|
175 |
-
st.
|
176 |
except Exception as e:
|
177 |
st.error(f"❌ Failed to load image: {e}")
|
|
|
|
|
|
48 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
49 |
|
50 |
# ------------------ Assistant Configuration ------------------
|
51 |
+
ASSISTANT_ID = "asst_jXDSjCG8LI4HEaFEcjFVq8KB" # Replace with your assistant ID
|
52 |
|
53 |
# ------------------ Session State ------------------
|
54 |
if "messages" not in st.session_state:
|
|
|
133 |
if m.role == "assistant":
|
134 |
reply = m.content[0].text.value
|
135 |
|
136 |
+
# ✂️ Optional: split out references
|
137 |
split_marker = "---"
|
138 |
if split_marker in reply:
|
139 |
main_answer, references = reply.split(split_marker, 1)
|
|
|
142 |
else:
|
143 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
144 |
|
145 |
+
# Extract raw GitHub-hosted image links
|
146 |
image_matches = re.findall(
|
147 |
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
|
148 |
reply
|
|
|
159 |
with st.chat_message("assistant" if msg["role"] != "references" else "📄"):
|
160 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
161 |
|
162 |
+
# ------------------ Slide Viewer (Horizontal Scroll) ------------------
|
163 |
with image_col:
|
164 |
if show_image and st.session_state.image_urls:
|
165 |
st.markdown("### 🖼️ Slide Previews")
|
166 |
+
|
167 |
+
st.markdown("""
|
168 |
+
<style>
|
169 |
+
.image-scroll-container {
|
170 |
+
display: flex;
|
171 |
+
overflow-x: auto;
|
172 |
+
gap: 16px;
|
173 |
+
padding: 0.5rem 0;
|
174 |
+
}
|
175 |
+
.image-scroll-container img {
|
176 |
+
height: 500px;
|
177 |
+
border-radius: 10px;
|
178 |
+
}
|
179 |
+
</style>
|
180 |
+
""", unsafe_allow_html=True)
|
181 |
+
|
182 |
+
st.markdown('<div class="image-scroll-container">', unsafe_allow_html=True)
|
183 |
+
|
184 |
+
for raw_url in st.session_state.image_urls:
|
185 |
try:
|
186 |
if "githubusercontent.com" not in raw_url:
|
187 |
continue
|
|
|
190 |
encoded_segments = [quote(seg) for seg in segments]
|
191 |
encoded_url = "https://raw.githubusercontent.com/" + "/".join(encoded_segments)
|
192 |
|
193 |
+
st.markdown(f'<img src="{encoded_url}" alt="slide" />', unsafe_allow_html=True)
|
194 |
except Exception as e:
|
195 |
st.error(f"❌ Failed to load image: {e}")
|
196 |
+
|
197 |
+
st.markdown('</div>', unsafe_allow_html=True)
|