vishwask commited on
Commit
ae5415f
·
1 Parent(s): 090c374

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -41
app.py CHANGED
@@ -167,11 +167,12 @@ if prompt := st.chat_input("How can I help you today?"):
167
  pix.save(output_image, "png")
168
  pdf_document.close()
169
  pdf_page_to_image('/home/user/app/pdf2image/output.pdf', page_number, '/home/user/app/pdf2image/output.png')
170
- image = Image.open('/home/user/app/pdf2image/output.png')
171
- message_placeholder.image(image)
172
- st.session_state.reference = True
173
-
174
 
 
 
175
  def generate_audio():
176
  sound_file = BytesIO()
177
  tts = gTTS(result['result'], lang='en')
@@ -186,18 +187,18 @@ 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()
@@ -205,33 +206,4 @@ if prompt := st.chat_input("How can I help you today?"):
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
-
237
 
 
167
  pix.save(output_image, "png")
168
  pdf_document.close()
169
  pdf_page_to_image('/home/user/app/pdf2image/output.pdf', page_number, '/home/user/app/pdf2image/output.png')
170
+ #image = Image.open('/home/user/app/pdf2image/output.png')
171
+ #message_placeholder.image(image)
172
+ #st.session_state.reference = True
 
173
 
174
+ st.session_state['reference'] = '/home/user/app/pdf2image/default_output.png'
175
+
176
  def generate_audio():
177
  sound_file = BytesIO()
178
  tts = gTTS(result['result'], lang='en')
 
187
  message_placeholder.markdown(full_response)
188
 
189
 
190
+ if "reference" not in st.session_state:
191
+ st.session_state.reference = False
192
  # if "audio" not in st.session_state:
193
  # st.session_state.audio = False
194
 
195
+ with st.sidebar:
196
+ choice = st.radio("References and TTS",["Reference"])
 
197
 
198
+ if choice == 'Reference':
199
+ generate_pdf()
200
+ st.session_state['reference'] = '/home/user/app/pdf2image/output.png'
201
+ st.image(st.session_state['reference'])
202
 
203
  # if choice == ':speaker:':
204
  # generate_audio()
 
206
 
207
 
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209