IAMTFRMZA commited on
Commit
3be5f75
·
verified ·
1 Parent(s): 045e703

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
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
- # ✅ 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
@@ -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 raw output
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: