Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -219,20 +219,25 @@ 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 |
for i, line in enumerate(lines):
|
226 |
-
clean_line = re.sub(r"
|
227 |
-
if "
|
228 |
-
|
229 |
-
if not
|
230 |
-
next_line = re.sub(r"
|
231 |
if next_line.startswith("http"):
|
232 |
-
|
233 |
-
if
|
234 |
-
image_urls.append(
|
|
|
235 |
st.session_state.image_results = [{"image": url} for url in image_urls]
|
|
|
|
|
|
|
|
|
236 |
break
|
237 |
except Exception as e:
|
238 |
st.error(f"❌ Visual Assistant Error: {e}")
|
@@ -243,6 +248,8 @@ with tab2:
|
|
243 |
if st.session_state.image_response:
|
244 |
st.markdown("### 🧠 Assistant Response")
|
245 |
st.markdown(st.session_state.image_response, unsafe_allow_html=True)
|
|
|
|
|
246 |
|
247 |
with image_col:
|
248 |
if st.session_state.image_results:
|
|
|
219 |
response_text = msg.content[0].text.value
|
220 |
st.session_state.image_response = response_text
|
221 |
|
222 |
+
# ✅ Robust URL extraction from markdown-formatted response
|
223 |
lines = response_text.splitlines()
|
224 |
image_urls = []
|
225 |
for i, line in enumerate(lines):
|
226 |
+
clean_line = re.sub(r"[*`]", "", line).strip().lower()
|
227 |
+
if "image url:" in clean_line:
|
228 |
+
url_candidate = line.split("Image URL:")[-1].strip()
|
229 |
+
if not url_candidate.startswith("http") and i + 1 < len(lines):
|
230 |
+
next_line = re.sub(r"[*`]", "", lines[i + 1].strip())
|
231 |
if next_line.startswith("http"):
|
232 |
+
url_candidate = next_line
|
233 |
+
if url_candidate.startswith("http"):
|
234 |
+
image_urls.append(url_candidate)
|
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
|
242 |
except Exception as e:
|
243 |
st.error(f"❌ Visual Assistant Error: {e}")
|
|
|
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 raw output
|
252 |
+
# st.code(st.session_state.image_response, language="markdown")
|
253 |
|
254 |
with image_col:
|
255 |
if st.session_state.image_results:
|