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:
|
@@ -134,7 +134,7 @@ with chat_col:
|
|
134 |
reply = m.content[0].text.value
|
135 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
136 |
|
137 |
-
#
|
138 |
image_matches = re.findall(
|
139 |
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n]+\.png',
|
140 |
reply
|
@@ -151,21 +151,21 @@ with chat_col:
|
|
151 |
with st.chat_message(msg["role"]):
|
152 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
153 |
|
154 |
-
# ------------------ Image
|
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 |
-
#
|
161 |
if "githubusercontent.com" not in raw_url:
|
162 |
continue
|
163 |
_, raw_path = raw_url.split("githubusercontent.com/", 1)
|
164 |
segments = raw_path.strip().split("/")
|
165 |
encoded_segments = [quote(seg) for seg in segments]
|
166 |
-
encoded_url =
|
167 |
|
168 |
-
# Load and display
|
169 |
r = requests.get(encoded_url)
|
170 |
r.raise_for_status()
|
171 |
img = Image.open(BytesIO(r.content))
|
|
|
48 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
49 |
|
50 |
# ------------------ Assistant Configuration ------------------
|
51 |
+
ASSISTANT_ID = "asst_jXDSjCG8LI4HEaFEcjFVq8KB" # Replace with your actual assistant ID
|
52 |
|
53 |
# ------------------ Session State ------------------
|
54 |
if "messages" not in st.session_state:
|
|
|
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
|
|
|
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)
|
164 |
segments = raw_path.strip().split("/")
|
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))
|