vishwask commited on
Commit
b5d563a
·
1 Parent(s): a1aedbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -15
app.py CHANGED
@@ -186,22 +186,51 @@ if prompt := st.chat_input("How can I help you today?"):
186
  message_placeholder.markdown(full_response)
187
 
188
 
189
- if "reference" not in st.session_state:
190
- st.session_state.reference = False
191
- if "audio" not in st.session_state:
192
- st.session_state.audio = False
193
-
194
- with st.sidebar:
195
- choice = st.radio("References and TTS",
196
- ["Reference", "Text-to-Speech"])
197
 
198
- if choice == 'Reference':
199
- st.session_state.reference = True
200
- generate_pdf()
201
-
202
- if choice == ':speaker:':
203
- generate_audio()
204
- st.session_state.audio = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
  st.session_state.messages.append({"role": "assistant", "content": full_response})
207
 
 
186
  message_placeholder.markdown(full_response)
187
 
188
 
189
+ # if "reference" not in st.session_state:
190
+ # st.session_state.reference = False
191
+ # if "audio" not in st.session_state:
192
+ # st.session_state.audio = False
193
+
194
+ # with st.sidebar:
195
+ # choice = st.radio("References and TTS",
196
+ # ["Reference", "Text-to-Speech"])
197
 
198
+ # if choice == 'Reference':
199
+ # st.session_state.reference = True
200
+ # generate_pdf()
201
+
202
+ # if choice == ':speaker:':
203
+ # generate_audio()
204
+ # st.session_state.audio = True
205
+
206
+
207
+
208
+ from streamlit.report_thread import get_report_ctx
209
+ from streamlit.server.server import Server
210
+
211
+ image_url = "/home/user/app/pdf2image/output.png" # Replace with your image URL
212
+ button_label = "Toggle Image"
213
+
214
+ # Check if the SessionState object exists, otherwise create a new one
215
+ ctx = get_report_ctx()
216
+ session_id = ctx.session_id
217
+ if session_id not in Server.get_current()._session_info:
218
+ Server.get_current()._session_info[session_id] = {}
219
+
220
+ session_state = Server.get_current()._session_info[session_id]
221
+
222
+ # Create a button to toggle the image visibility
223
+ toggle_button = st.button(button_label, key=session_id)
224
+
225
+ # Check if the toggle button is pressed
226
+ if toggle_button:
227
+ # Store the current state of the button in the session state
228
+ session_state[session_id] = not session_state.get(session_id, False)
229
+
230
+ # Check if the image should be displayed based on the session state
231
+ if session_state.get(session_id, False):
232
+ # Display the image
233
+ st.image(image_url, caption='Image Caption')
234
 
235
  st.session_state.messages.append({"role": "assistant", "content": full_response})
236