Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -219,23 +219,26 @@ with tab2:
|
|
| 219 |
response_text = msg.content[0].text.value
|
| 220 |
st.session_state.image_response = response_text
|
| 221 |
|
| 222 |
-
# ✅
|
| 223 |
lines = response_text.splitlines()
|
| 224 |
image_urls = []
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
st.session_state.image_results = [{"image": url} for url in image_urls]
|
| 237 |
|
| 238 |
-
# Optional: auto-preview first image
|
| 239 |
if image_urls and not st.session_state.image_lightbox:
|
| 240 |
st.session_state.image_lightbox = image_urls[0]
|
| 241 |
break
|
|
@@ -248,7 +251,7 @@ with tab2:
|
|
| 248 |
if st.session_state.image_response:
|
| 249 |
st.markdown("### 🧠 Assistant Response")
|
| 250 |
st.markdown(st.session_state.image_response, unsafe_allow_html=True)
|
| 251 |
-
# Optional: Debug
|
| 252 |
# st.code(st.session_state.image_response, language="markdown")
|
| 253 |
|
| 254 |
with image_col:
|
|
|
|
| 219 |
response_text = msg.content[0].text.value
|
| 220 |
st.session_state.image_response = response_text
|
| 221 |
|
| 222 |
+
# ✅ FINAL FIXED PARSER: Handles Image URL on next line
|
| 223 |
lines = response_text.splitlines()
|
| 224 |
image_urls = []
|
| 225 |
+
expecting_url = False
|
| 226 |
+
|
| 227 |
+
for line in lines:
|
| 228 |
+
line_clean = line.strip().replace("**", "")
|
| 229 |
+
if "Image URL:" in line_clean:
|
| 230 |
+
parts = line_clean.split("Image URL:")
|
| 231 |
+
if len(parts) > 1 and parts[1].strip().startswith("http"):
|
| 232 |
+
image_urls.append(parts[1].strip())
|
| 233 |
+
else:
|
| 234 |
+
expecting_url = True # Flag next line
|
| 235 |
+
elif expecting_url:
|
| 236 |
+
if line_clean.startswith("http"):
|
| 237 |
+
image_urls.append(line_clean)
|
| 238 |
+
expecting_url = False
|
| 239 |
|
| 240 |
st.session_state.image_results = [{"image": url} for url in image_urls]
|
| 241 |
|
|
|
|
| 242 |
if image_urls and not st.session_state.image_lightbox:
|
| 243 |
st.session_state.image_lightbox = image_urls[0]
|
| 244 |
break
|
|
|
|
| 251 |
if st.session_state.image_response:
|
| 252 |
st.markdown("### 🧠 Assistant Response")
|
| 253 |
st.markdown(st.session_state.image_response, unsafe_allow_html=True)
|
| 254 |
+
# Optional: Debug
|
| 255 |
# st.code(st.session_state.image_response, language="markdown")
|
| 256 |
|
| 257 |
with image_col:
|