IAMTFRMZA commited on
Commit
36fcb18
ยท
verified ยท
1 Parent(s): 90cb5dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -206,8 +206,9 @@ with tab2:
206
  response_text = msg.content[0].text.value.strip()
207
  st.session_state.image_response = response_text
208
 
209
- # โœ… Robust markdown block parser
210
- blocks = response_text.split("### ๐Ÿ–ผ๏ธ")[1:]
 
211
  results = []
212
  for b in blocks:
213
  lines = b.strip().splitlines()
@@ -217,10 +218,10 @@ with tab2:
217
  "url": ""
218
  }
219
  for line in lines:
220
- if line.startswith("- **Description:**"):
221
- card["desc"] = line.replace("- **Description:**", "").strip()
222
- elif line.startswith("- **Image URL:**"):
223
- card["url"] = line.replace("- **Image URL:**", "").strip()
224
  elif line.startswith("http") and not card["url"]:
225
  card["url"] = line.strip()
226
  if card["url"]:
@@ -243,16 +244,17 @@ with tab2:
243
  item = st.session_state.image_results[idx]
244
  with col:
245
  try:
246
- img = Image.open(BytesIO(requests.get(item["url"]).content))
247
- st.image(img, use_container_width=True)
248
  except:
249
  st.image("https://via.placeholder.com/150?text=Image+Error", use_container_width=True)
250
 
251
  st.markdown(f"**{item.get('title', 'No Title')}**", unsafe_allow_html=True)
252
- st.caption(item.get("desc", "")[:150] + "..." if item.get("desc") else "")
253
  if st.button("๐Ÿ” View", key=f"img_{idx}"):
254
  st.session_state.image_lightbox = item["url"]
255
 
 
256
  if st.session_state.image_lightbox:
257
  st.markdown("### ๐Ÿ”ฌ Full Image View")
258
  try:
 
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()
 
218
  "url": ""
219
  }
220
  for line in lines:
221
+ if "Description:" in line:
222
+ card["desc"] = line.split("Description:")[1].strip()
223
+ elif "Image URL:" in line:
224
+ card["url"] = line.split("Image URL:")[1].strip()
225
  elif line.startswith("http") and not card["url"]:
226
  card["url"] = line.strip()
227
  if card["url"]:
 
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: