IAMTFRMZA commited on
Commit
5c33d13
ยท
verified ยท
1 Parent(s): 36fcb18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -23
app.py CHANGED
@@ -206,9 +206,8 @@ with tab2:
206
  response_text = msg.content[0].text.value.strip()
207
  st.session_state.image_response = response_text
208
 
209
- # โœ… Robust parser (works for ๐Ÿ–ผ๏ธ lines and "Image URL:" labels)
210
- import re
211
- blocks = re.split(r"(?:###\s)?๐Ÿ–ผ๏ธ", response_text)[1:]
212
  results = []
213
  for b in blocks:
214
  lines = b.strip().splitlines()
@@ -233,28 +232,22 @@ with tab2:
233
  except Exception as e:
234
  st.error(f"โŒ Assistant Error: {e}")
235
 
236
- # ๐Ÿ–ผ๏ธ Display Image Cards in 4-column layout
237
  if st.session_state.image_results:
238
  st.markdown("### ๐Ÿ–ผ๏ธ Image Results")
239
- for i in range(0, len(st.session_state.image_results), 4):
240
- row = st.columns(4)
241
- for j, col in enumerate(row):
242
- idx = i + j
243
- if idx < len(st.session_state.image_results):
244
- item = st.session_state.image_results[idx]
245
- with col:
246
- try:
247
- img_data = requests.get(item["url"], timeout=10).content
248
- st.image(Image.open(BytesIO(img_data)), use_container_width=True)
249
- except:
250
- st.image("https://via.placeholder.com/150?text=Image+Error", use_container_width=True)
251
-
252
- st.markdown(f"**{item.get('title', 'No Title')}**", unsafe_allow_html=True)
253
- st.caption(item.get("desc", "")[:160] + "..." if item.get("desc") else "")
254
- if st.button("๐Ÿ” View", key=f"img_{idx}"):
255
- st.session_state.image_lightbox = item["url"]
256
-
257
- # ๐Ÿ”ฌ Full Image Lightbox Viewer
258
  if st.session_state.image_lightbox:
259
  st.markdown("### ๐Ÿ”ฌ Full Image View")
260
  try:
 
206
  response_text = msg.content[0].text.value.strip()
207
  st.session_state.image_response = response_text
208
 
209
+ # โœ… Reliable parser for markdown blocks
210
+ blocks = response_text.split("### ๐Ÿ–ผ๏ธ")[1:]
 
211
  results = []
212
  for b in blocks:
213
  lines = b.strip().splitlines()
 
232
  except Exception as e:
233
  st.error(f"โŒ Assistant Error: {e}")
234
 
235
+ # ๐Ÿ–ผ๏ธ Display images in vertical stack
236
  if st.session_state.image_results:
237
  st.markdown("### ๐Ÿ–ผ๏ธ Image Results")
238
+ for idx, item in enumerate(st.session_state.image_results):
239
+ try:
240
+ img = Image.open(BytesIO(requests.get(item["url"], timeout=10).content))
241
+ st.image(img, use_container_width=True)
242
+ except:
243
+ st.image("https://via.placeholder.com/150?text=Image+Error", use_container_width=True)
244
+
245
+ st.markdown(f"**{item.get('title', 'No Title')}**", unsafe_allow_html=True)
246
+ st.caption(item.get("desc", "")[:200] + "..." if item.get("desc") else "")
247
+ if st.button("๐Ÿ” View", key=f"img_{idx}"):
248
+ st.session_state.image_lightbox = item["url"]
249
+
250
+ # ๐Ÿ”ฌ Full image lightbox
 
 
 
 
 
 
251
  if st.session_state.image_lightbox:
252
  st.markdown("### ๐Ÿ”ฌ Full Image View")
253
  try: