IAMTFRMZA commited on
Commit
7049f1a
·
verified ·
1 Parent(s): 572b94e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -213,23 +213,17 @@ with tab2:
213
  except Exception as e:
214
  st.error(f"Error: {e}")
215
 
216
- # Render assistant response and display images using 'Image URL' field
217
  if st.session_state.image_response:
218
  st.markdown("### 🧠 Assistant Response")
219
  st.markdown(st.session_state.image_response, unsafe_allow_html=True)
220
 
221
- # Extract full GitHub URLs from assistant output
222
  url_matches = re.findall(r'Image URL:\s*(https?://[^\s]+)', st.session_state.image_response)
223
 
224
  for url in url_matches:
225
- st.markdown(f"🔗 [View image directly]({url})")
226
-
227
  try:
228
- r = requests.get(url, timeout=5)
229
- r.raise_for_status()
230
- img = Image.open(BytesIO(r.content))
231
- st.image(img, caption=url.split("/")[-1], use_container_width=True)
232
  except Exception as e:
233
- st.warning(f"⚠️ Failed to load: {url}")
234
  st.error(f"🛑 Error: {str(e)}")
235
-
 
213
  except Exception as e:
214
  st.error(f"Error: {e}")
215
 
216
+ # Render assistant response and load each image using the actual URL
217
  if st.session_state.image_response:
218
  st.markdown("### 🧠 Assistant Response")
219
  st.markdown(st.session_state.image_response, unsafe_allow_html=True)
220
 
221
+ # Extract valid GitHub URLs from assistant response
222
  url_matches = re.findall(r'Image URL:\s*(https?://[^\s]+)', st.session_state.image_response)
223
 
224
  for url in url_matches:
 
 
225
  try:
226
+ st.image(url, caption=url.split("/")[-1], use_container_width=True)
 
 
 
227
  except Exception as e:
228
+ st.warning(f"⚠️ Could not load image: {url}")
229
  st.error(f"🛑 Error: {str(e)}")