Spaces:
Running
Running
Update app.py
Browse files
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
|
210 |
-
|
|
|
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
|
221 |
-
card["desc"] = line.
|
222 |
-
elif
|
223 |
-
card["url"] = line.
|
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 |
-
|
247 |
-
st.image(
|
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", "")[:
|
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:
|