devchavda11 commited on
Commit
6b4a743
·
verified ·
1 Parent(s): 35b0e49

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +15 -11
src/streamlit_app.py CHANGED
@@ -85,6 +85,13 @@ def create_download_link(file_path: str, label: str = "Download file") -> str:
85
  return f"Error creating download link: {e}"
86
 
87
 
 
 
 
 
 
 
 
88
  load_session_state()
89
  render_sidebar()
90
 
@@ -109,18 +116,15 @@ if "current_chat_id" in st.session_state:
109
  if isinstance(messages, ToolMessage) and messages.content.strip():
110
  st.info(f"Using appropriate tool")
111
 
112
- # If tool output contains file creation info → show download link
 
 
 
 
 
113
  if "Content saved to" in messages.content:
114
  file_name = messages.content.replace("Content saved to ", "").strip()
115
- file_path = os.path.join(TEMP_DIR, file_name)
116
- if os.path.exists(file_path):
117
- st.markdown(
118
- create_download_link(file_path, "📥 Download File"),
119
- unsafe_allow_html=True
120
- )
121
 
122
  response_placeholder.markdown(full_response)
123
-
124
-
125
-
126
-
 
85
  return f"Error creating download link: {e}"
86
 
87
 
88
+ def show_image_with_download(file_path: str):
89
+ """Display image in chat and show a download button."""
90
+ if os.path.exists(file_path) and file_path.endswith(".png"):
91
+ st.image(file_path, caption=os.path.basename(file_path))
92
+ st.markdown(create_download_link(file_path, "📥 Download Image"), unsafe_allow_html=True)
93
+
94
+
95
  load_session_state()
96
  render_sidebar()
97
 
 
116
  if isinstance(messages, ToolMessage) and messages.content.strip():
117
  st.info(f"Using appropriate tool")
118
 
119
+ # Detect generated PNG files and show + download them
120
+ file_matches = re.findall(r"/tmp/[\w\.\-_]+\.png", messages.content)
121
+ for file_path in file_matches:
122
+ show_image_with_download(file_path)
123
+
124
+ # Existing logic for "Content saved to"
125
  if "Content saved to" in messages.content:
126
  file_name = messages.content.replace("Content saved to ", "").strip()
127
+ if os.path.exists(file_name):
128
+ show_image_with_download(file_name)
 
 
 
 
129
 
130
  response_placeholder.markdown(full_response)